我正在编写一个程序来搜索结构 vector 中的值范围,尝试了将近一天之后,我仍然不走运
这是我在做的,我知道这是错误的
{在函数中}
vector::iterator it=find_if(ip_records[ip].begin(),ip_records[ip].end(), find_it("2011-01-24 20:59.20", "2011-01-24 20:59.30"));
{定义}
struct find_it {<br/>
string start, end;<br/>
find_it(string start, string end):start(start){}<br/>
bool operator()(record const& r) const {<br/>
if ((strcmp(r.start_time.c_str(), start.c_str()) >= 0) && (strcmp(r.start_time.c_str(), end.c_str()) <= 0)){<br/>
return true;<br/>
}<br/>
}<br/>
我无法在 find_it() 中接收 2 个字符串作为参数
这里有一些我找不到解决方案的链接
Vectors, structs and std::find
Searching c++ std vector of structs for struct with matching string
谢谢
感谢任何帮助
最佳答案
你没有初始化初始化列表中的end
成员变量:
find_it(string start, string end):start(start), end(end) {}
//note this ^^^^^^^^
现在,它初始化它!
关于c++ - 在结构 vector C++ 中搜索值的范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5109499/