⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 p12_2.cpp

📁 相当丰富的C++源码
💻 CPP
字号:
/***********************************************
*   p12_2.cpp                                  *
*   string类的成员函数的使用,字符串查找与替换 *
***********************************************/
#include <string>
#include <iostream>
using namespace std;
void main()
{
	string text("I like c++, "
		        "I use c++ programming."); //文本
	string newstr;                        //新串
	string sstr;                          //待查串
	int pos;                              //存放查找到串的位置
	cout<<"Input string and new string:";
	cin>>sstr>>newstr;
	if((pos=text.find(sstr))==string::npos) //未查找到
		cout<<sstr<<" not found in \""<<text<<"\""<<endl;
	else {
        cout<<"old string: "<<text<<endl;
	    text.replace(pos,sstr.length(),newstr);
		cout<<"new string: "<<text<<endl;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -