我写了个字符串子串位置查询的语句,用的是string的find_first_of,可是令我没有想到的是,这个函数并没有我想像的那么好。
例如:
         string name = "ceshiceshi";
string::size_type pos = 0;
string hz = "c";
vector<int> vec; 
while(( pos = name.find_first_of(hz.c_str(),pos)) != string::npos )
{ //pvec[pos].push_back(recNo);
//off_set.insert(pos);
vec.push_back(pos);
++pos;
}vector里面会有两个值,0和5;
可似乎我把hz="ce"后,本以为会出现0和5,没想到出现了4个值,这是怎么回事呢,如果我想去找一个子串在一个字符串中的位置,难道stl不提供这个算法吗,难道还要我自己写个kmp算法?我觉得stl应该有这个功能,哪位知道呢,请赐教!