现在的位置: 首页 > 综合 > 正文

键盘循环不断输入字符串,查找指定字符串并更改替换指定字符串

2014年09月05日 ⁄ 综合 ⁄ 共 355字 ⁄ 字号 评论关闭

回答百度问题,在这里也顺便总结下:

// 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;
}

 

抱歉!评论已关闭.