64,654
社区成员
发帖
与我相关
我的任务
分享
#include<string>
#include<iostream>
using namespace std;
int main()
{
string strContent="xiaohai+chunxiao";
string::size_type pos;
//while((pos = strContent.find("+") )!= string::npos)//去掉+
//{
// strContent.replace(pos,1,"");
//}
while((pos = strContent.find("+") )!= string::npos)//去掉+
{
strContent.replace(pos,1,"");
}
cout<<strContent<<endl;
return 0;
}
输出的结果是:xiaohai玞hunxiao
#include<string>
#include<iostream>
using namespace std;
int main()
{
wstring strContent=L"xiaohai+chunxiao";
wstring::size_type pos;
//while((pos = strContent.find("+") )!= string::npos)//去掉+
//{
// strContent.replace(pos,1,"");
//}
while((pos = strContent.find(L"+") )!= wstring::npos)//去掉+
{
strContent.replace(pos,1,L"");
}
wcout<<strContent<<endl;
return 0;
}