#include <iostream>
#include <string>
#include <vector>
using namespace std;
#include<algorithm>
int main()
{ //while(getline(cin,s)):输入带有空格的字符;
string s1(2,'c'),s("value");
cout<<s1<<endl;
s=s+"abcd";
cout<<s<<endl;
s.append("123"); //在字符串s后面添加123
cout<<s<<endl;
s.insert(s.begin()+2,'9');
cout<<s<<endl;
cout<<s[2]<<endl;
s.erase(s.begin()+3);
cout<<s<<endl;
s.erase(s.begin(),s.begin()+3);
cout<<s<<endl;
s.replace(3,6,"good"); //从第3个开始,将连续的6个字符替换为good
cout<<s<<endl;
cout<<s.size()<<endl;
cout<<s.find("good")<<endl;
cout<<s.find('z')<<endl;
reverse(s.begin(),s.begin()+5);
cout<<s<<endl;
cout<<s.compare("aaa")<<endl;//s与“aaa”比较大小;
cout<<s.compare("zzz")<<endl;
cout<<s.compare("ogaeuod")<<endl;
vector<string>v;
char s5[50]="jack",s2[50]="mike",s3[50]="tom";
v.push_back(s5);
v.push_back(s2);
v.push_back(s3);
cout<<v[0]<<endl;
cout<<v[1][0]<<endl;
cout<<v[1].size()<<endl;
return 0;
}
string 的基本操作
最新推荐文章于 2022-08-28 22:31:35 发布