首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

C++的string的这个find成员函数是咋回事啊

2012-02-28 
C++的string的这个find成员函数是怎么回事啊?C/C++ codestring replace_string(string &strSrc, const str

C++的string的这个find成员函数是怎么回事啊?

C/C++ code
string replace_string(string &strSrc, const string &strOld, const string &strNew){    string::size_type pos(0);        while (pos = strSrc.find(strOld , pos) != string::npos)    {        strSrc.replace(pos, strOld.length(), strNew);        pos += strNew.length();        cout << pos << '\t' << strSrc << endl;    }        return strSrc;}int main(void){    string strTest("2001,1,1,23,12,3,1,33,12,");    string strOut = replace_string(strTest, ",", "|");    cout << strOut << endl;        system("pause");    return 0;}


一直都无法正常输出,查了一下,原来在replace_string函数里死循环了
输出的一直都是1 2 01,1,1,23,12,3,1,33,12,
我不明白,find无法在2001,1,1,23,12,3,1,33,12,这样一个字符串里正常查找到逗号这个字符

[解决办法]
while ((pos = strSrc.find(strOld , pos)) != string::npos)

热点排行