#include <iostream> #include <string> using namespace std; inline string& replace_all(string& str, const string& old_value, const string& new_value) { while (true) { string::size_type pos(0); pos = str.find(old_value); //cout <<pos<< endl; if ( (pos = str.find(old_value)) != string::npos ) str.replace(pos, old_value.length(), new_value); else break; } return str; } int main() { string strInfo="硚"; string::size_type pos(0); string strInfo1="~"; pos =strInfo.find(strInfo1); cout <<pos<< endl; strInfo = replace_all(strInfo, "~", "#$");// cout <<strInfo<< endl; // prints !!!Hello World!!! }
烦请大神解答下,string strInfo="硚"; 不包含 字符 ~,使用find也返回1
onemoo
相关分类