#include <string>
#include <iostream>
using namespace std;
int main()
{
string show;
string show2="aaaa";
show="bbbb";
cout<<"交换两个字符串的内容"<<endl;
show.swap(show2);
cout<<show<<endl;
cout<<show2<<endl;
cout<<endl;
cout<<"测试是否为空"<<endl;
cout<<show.empty()<<endl;
cout<<show<<endl;
cout<<endl;
cout<<"找集合sset= abcz 中的某个字符在内容words中第一次出现的位置"<<endl;
string words="abcdefghijklmnopqrstuvwxyz";
string sset="bhcz";
cout<<words.find_first_of(sset )<<endl;
cout<<words.find_last_of(sset)<<endl;
cout<<endl;
cout<<"查找某一个串的位置"<<endl;
string::size_type fpos =words.find("def");
if(fpos!= string::npos)
{
cout<<fpos<<endl;
}
cout<<endl;
cout<<"以某个串a替换串b"<<endl;
string strsrc="a";
string strdst="bbb";
string::size_type pos=0;
string::size_type srclen=strsrc.size();
string::size_type dstlen=strdst.size();
while( (pos=words.find(strsrc, pos)) != string::npos)
{words.replace(pos, srclen, strdst); pos += dstlen;}
cout<<words<<endl;
words="1234567890";
cout<<endl;
cout<<"从索引1开始的2个字符替换成后面的string"<<endl;
words.replace(1,2,"n ");
cout<<words<<endl;
cout<<endl;
cout<<words<<endl;
cout<<"删除索引从a开始的b个字符串"<<endl;
words.erase(0,1);
cout<<words<<endl;
cout<<endl;
cout<<"输入一行,以' '结尾"<<endl;
//getline(cin,words,' ');
cout<<words<<endl;
words="123456";
cout<<endl;
cout<<"从索引a开始的b个串"<<endl;
show=words.substr(1,3);
cout<<show<<endl;
cout<<endl;
cout<<"TrimRinght和TrimLeft"<<endl;
words=" 123 456 _ 789 ";
words.erase(words.find_last_not_of(' ')+1,words.size());
words.erase(0,words.find_first_not_of(' '));
cout<<words<<endl;
words.insert(1,"hello!");
return 0;
}