您的位置:首页 > 编程语言 > C语言/C++

c++ STL string类的查找、替换和删除操作

2013-11-23 22:27 211 查看
#include "stdafx.h"
#include <iostream>
#include <string>
using std::string;
using std::cin;
using std::cout;
using std::endl;

int _tmain(int argc, _TCHAR* argv[])
{
string strContent = "www.jiesoon.com is a exciting site for all C/C++ developers! www.jiiesoon.cn is a sub-site in China.";

//查找
string::size_type nPos = strContent.find("jiesoon", 0); //从0位置开始查找
if(nPos != string::npos){
cout << "find jeasoon on" << nPos << endl;
}
else{
cout << "Can't find jeasoon on offset 0" << endl;
}

//删除
strContent.erase(4, 7);
cout << strContent << endl;

//替换
strContent.replace(4, 7, "JIESOON");
cout << strContent << endl;

getchar();
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐