C++ STL String学习
#include<iostream>
#include<string>
using namespace std;
int test_string()
{
string s1 = "aaa";
string s4 = string("dddd");
string s2 = string(s1);
string s3 = string(s1, 0, 2);
s2 = s2 + "bb";
s1 = s1 + "ccc";
cout << s1 << ' ' << s2 <<' '<<s3<<' '<<s4<< endl;
string str = "hello world";
char c = s1[0];
cout << c<<endl;
string str1 = str.substr(1);
cout << str1 << endl;
str1 = str.substr(1, 6);
cout << str1 << endl;
str1.insert(1, "s");
cout << str1 << endl;
str1.insert(1, 1, 'z');
cout << str1<<endl;
str1.erase(5, 2);
cout << str1 << endl;
string::iterator it = str1.begin();
str1.erase(str1.begin());
cout << str1 << endl;
str1.erase(str1.begin() + 2, str1.end() - 1);
cout << str1 << endl;
str1.append("hello", 2, 3);
cout << str1 << endl;
s1 = "world";
str1.append(s1, 2);
cout << str1 << endl;
str1.replace(0, 3, "you");
cout << str1 << endl;
s1 = "worldo";
cout<<s1.find('o')<<endl;
cout << s1.rfind('o') << endl;
int a = 256;
string as = to_string(a);
cout << as << endl;
cout << "字符串转换为10进制整数:" << stoi(as, 0) << endl;
system("pause");
return 0;
}