开发者

Searching range of values in a Vector of Structs C++

I am writing a program to search range of values in a vector of structs, after trying for almost a day, I am still out of luck

Here is what I am doing, I know it is wrong

{in Function}

vector::iterator it=find_if(ip_records[ip].begin(),ip_records[ip].end(), find_it("2011-01-24 20:59.20", "2011-01-开发者_JAVA技巧24 20:59.30"));

{Defn}

struct find_it {

string start, end;

find_it(string start, string end):start(start){}

bool operator()(record const& r) const {

if ((strcmp(r.start_time.c_str(), start.c_str()) >= 0) && (strcmp(r.start_time.c_str(), end.c_str()) <= 0)){

return true;

}

}

I am not able to receive 2 string as parameters in find_it()

Here are some links from which I could not find solution

Vectors, structs and std::find

Searching c++ std vector of structs for struct with matching string

Thank you

Any help is appreciated


You didn't initialize the end member variable in the initialization-list:

find_it(string start, string end):start(start), end(end) {}
                                    //note this ^^^^^^^^

Now, it initializes it!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜