string a;/////指定串,可根據要求替換
string b;////要查找的串,可根據要求替換
string c;
cin>>a>>b>>c;
int pos;
pos = a.find(b);////查找指定的串
while (pos != -1)
{
a.replace(pos,b.length(),c);////用新的串替換掉指定的串
pos = a.find(b);//////繼續查找指定的串,直到所有的都找到為止
}
cout<<a<<endl;
string a;/////指定串,可根據要求替換
string b;////要查找的串,可根據要求替換
string c;
cin>>a>>b>>c;
int pos;
pos = a.find(b);////查找指定的串
while (pos != -1)
{
a.replace(pos,b.length(),c);////用新的串替換掉指定的串
pos = a.find(b);//////繼續查找指定的串,直到所有的都找到為止
}
cout<<a<<endl;
本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。