我想知道在字符串中的 “_” 的位置:如何检测C++字符串中的“_”?
string str("BLA_BLABLA_BLA.txt");
喜欢的东西:
string::iterator it;
for (it=str.begin() ; it < str.end(); it++){
if (*it == "_") //this goes wrong: pointer and integer comparison
{
pos(1) = it;
}
cout << *it << endl;
}
感谢, 安德烈
尝试使用单引号而不是双引号。 – 2010-09-16 10:06:58
@多米尼克为什么不是这个答案? – Motti 2010-09-16 10:34:39
@Motti - 现在是(见sbi的答案http://stackoverflow.com/questions/3725574/detect-in-a-string/3725671#3725671) – 2010-09-16 10:47:39