参考链接: 用C++程序删除字符串中除字母之外的所有字符 。
// StringTest.cpp : 定义控制台应用程序的入口点。 //
#include "stdafx.h" //#include <cstddef> #include "string" #include "iostream";
using namespace std; string& ReplaceAll(string& context,const string &from,const string& to) {
size_t lookHere=0; size_t foundHere; while((foundHere=context.find(from,lookHere))!=string::npos) { context.replace(foundHere,from.size(),to); lookHere=foundHere+to.size(); } return context;
}
int _tmain(int argc, _TCHAR* argv[]) {
//tets string test="my name is /,/ is a good sutdent"; cout<<ReplaceAll(test,"/","justin")<<endl; int k=0; cin>>k;
return 0; }
本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。
本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。