0
我想設置lower_bound和upper_bound以便多重結構遍歷一個範圍。如何正確設置字符串?在stl集中設置lower_bound
#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;
}
我該如何設置低指向字符串測試以「ab」開頭的元素?
我想:
itLow = fooset.lower_bound("string");
我知道這是不夠的......但我不知道該怎麼做。
謝謝!
及其'foo'一個構造函數,可以讓你通過在一個字符串中,它被用來初始化'test'。 – 2012-03-22 18:30:10
當我嘗試對此進行測試時,我得到了最後一行的「從這裏實例化」的錯誤。 另外...當我將'lower_bound'更改爲'upper_bound'時,我無法解決錯誤。有任何想法嗎?謝謝! – 2012-03-22 18:39:36
@JayKim:糟糕 - 當您指定比較函數而不是使用'operator <'時,您還必須將它傳遞給'lower_bound',就像'std :: multiset :: iterator it = std :: lower_bound(fooset .begin(),fooset.end(),foo(「string」),comp());' –
2012-03-22 22:50:51