I want to set the lower_bound and upper_bound for a multiset of structs to iterate through a range. How do I set it correctly for strings?
#include ...
...
struct foo{
int bar;
string test;
};
struct comp{
inline bool operator()(const foo& left,const foo& right){
return strcasecmp(left.test.c_str(), right.test.c_str());
}
};
int main(){
std::multiset<foo,comp> fooset;
std::multiset<foo,comp>::iterator it, itLow;
...//insert into fooset
//how do set lower_bound to element where string is "aab" or whatever?
return 0;
}
How can I set itLow to point to the element with string test starting with “ab”?
I tried:
itLow = fooset.lower_bound("string");
I know that’s not sufficient…but I’m not sure how to do it.
Thanks!
You need to construct a
foofrom the string, then uselower_bound(orupper_bound, as he case may be) to search for the position: