C++ 如何从string中删除一个字符?

来源:互联网 发布:linux cdn 编辑:程序博客网 时间:2024/04/29 06:22
#include #include #include #include using namespace std;int main(){ string str = "abcdfccccefg"; string::iterator new_end = remove_if(str.begin(), str.end(), bind2nd(equal_to(), 'c')); str.erase(new_end, str.end()); cout << str << endl;string abc = "123'''''456"; int nPos = abc.find_first_of( '\'' ); if ( nPos != string::npos ) { abc = abc.substr( 0 , nPos ) + abc.substr( nPos + 1 , -1 ); } //else // break;cout<<abc; return 0;}
0 0
原创粉丝点击