回答百度问题,在这里也顺便总结下:
// tesWeb.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <string>
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
string a;/指定串,可根据要求替换
string b;要查找的串,可根据要求替换
string c;
int pos;
while ( cin >> a>>b>>c){
pos = a.find(b);
while(pos != -1)
{
a.replace(pos++,b.length(),c);用新的串替换掉指定的串
pos = a.find(b);
}
cout<< a.c_str() <<endl;
}
return 0;
}