#include <iostream>
#include <string>
using namespace std;
int main() {
string str1;
str1 = "1234546ssshhhhh";
string str2 = "i love you";
string str3 = str1 + " " + str2;
string str5(str3);
cout << str1 << endl;
cout << str2 << endl;
cout << str3 << endl;
cout << str1[3] << endl;
cout << str5 << endl;
int str11 = str1.length();
int str12 = str1.size();
cout << " str1.length()= " << str11 << endl;
cout << " str1.size()= " << str12 << endl;
cout << " str1.empty()= " << str1.empty() << endl;
swap(str1, str2);
cout << " str1= " << str1 << endl;
cout << " str2= " << str2 << endl;
str1.push_back(48);
str1.append("skk");
str1.append("skk");
str1 += "99666";
cout << " str1= " << str1 << endl;
str1.assign("1234546");
cout << " str1= " << str1 << endl;
str1 = "2333333";
cout << " str1= " << str1 << endl;
for (int i = 0;i < str1.length();i++) {
cout << " str1[" << i << "]= " << str1[i] << endl;
}
str1.insert(str1.begin() + 2,'6');
cout << " str1= " << str1 << endl;
str1.erase(str1.begin() + 2,str1.end()-2);
cout << " str1= " << str1 << endl;
str1 = "aaaaaaaaaa";
str3 = "123456789123455556t";
str1=str1.replace(str1.find("a"),9,"b");
cout << " str1= " << str1 << endl;
str3 = str3.replace(str3.begin() + 1, str3.begin() + 5, "!!!!!!!!!!");
cout << " str3= " << str3 << endl;
str3 = str3.replace(0, 1, str2, str2.find("3"), 9);
cout << " str3= " << str3 << endl;
string::size_type position;
position = str3.find("123");
cout << " the position is " << position << endl;
cout << " str3.capacity()= " << str3.capacity() << endl;
cout << " str3.length()= " << str3.length() << endl;
char* s=(char*)str3.data();
cout << s[2] << s[3] << s[4] << endl;
str3.clear();
cout << str3 << s[3] << endl;
cout << str2.max_size() << endl;
str2.reserve();
str2.resize(3);
cout << str2 << endl;
cout << str2.capacity() << endl;
string str6 = "123456789123456789123456789";
cout << " str6= " << str6 << endl;
str2=str6.substr(9);
cout << " str2= " << str2 << endl;
}
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/67607f600130ad5b94798a196bb7db96.png)