c++ - 在结构 vector C++ 中搜索值的范围

标签 c++ vector struct

我正在编写一个程序来搜索结构 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/

相关文章:

C 结构和指针

arrays - 如何在 BigQuery 中声明列表/数组/结构类型变量

c++ - 在循环中创建 100 个具有不同名称的对象

c++ - 使用 C++ 实现事件日志

c++ - ReadWrite lock using Boost.Threads(如何转换这个简单的类)

c++ - C++ 的 Quicktime API

c++ - vector 如何按值传递?

C++索引超出范围但没有在应该发生的时候发生

c++ STL vector 导致内存溢出?

C 编程,将结构体中的 int 成员分配给整数时出现段错误