我有一个消息列表,每次添加消息时,我都会设置一个时间戳。我正在尝试创建一个函数,该函数将返回在一定时间内添加的消息,该消息也与字符串匹配。但是,我现在卡住了,非常感谢任何帮助,下面是我的代码:
struct BarMessage
{
int Length;
const char *message;
time_t TimeAdded;
};
struct Ba
{
vector<BarMessage> Messages;
void AddMessage(const char *message, int Length)
{
BarMessage m;
m.message = message;
m.Length = Length;
time(&m.TimeAdded); // set time ?
Messages.push_back(m);
}
BarMessage & GetMessageWithin(string pattern, int span = 200)
{
//Time.Now?
time_t now;
time(&now);
if (this->Messages.size() > 0)
{
for (auto & messages : this->Messages)
{
//Stuck here!!!
//I want to return the BarMessage of a message
//that was added within 200 (span)
//that also contains the string patten inside it
}
}
}
};