1.string 构造函数
string();
string(const string& str);
string(const char* s);
string(int n, char c);
2 string基本赋值操作
string& operator=(const char* s);
string& operator=(const string &s);
string& operator=(char c);
string s;
s.assign();
string& assign(const char *s);
string& assign(const char *s, int n);
string& assign(const string &s);
string& assign(int n, char c);
string& assign(const string &s, int start, int n);
3 string存取字符操作
char& operator[](int n);
char& at(int n);
4 string拼接操作
string s;
s+="a";
string& operator+=(const string& str);
string& operator+=(const char* str);
string& operator+=(const char c);
s.append();
string& append(const char *s);
string& append(const char *s, int n);
string& append(const string &s);
string& append(const string &s, int pos, int n);
string& append(int n, char c);
5 string查找和替换
int find(const string& str, int pos = 0) const;
int find(const char* s, int pos = 0) const;
int find(const char* s, int pos, int n) const;
int find(const char c, int pos = 0) const;
int rfind(const string& str, int pos = npos) const;
int rfind(const char* s, int pos = npos) const;
int rfind(const char* s, int pos, int n) const;
int rfind(const char c, int pos = 0) const;
string& replace(int pos, int n, const string& str);
string& replace(int pos, int n, const char* s);
6 string子串
string substr(int pos = 0, int n = npos) const;
6.1 substr 和 find 可以组合特殊操作
string email = "zhang666@abcd.com";
int pos = email.find("@");
cout << "pos " << pos << endl;
string usrName = email.substr(0, pos);
cout << "用户名为:" << usrName << endl;
7 string比较操作
int compare(const string &s) const;
int compare(const char *s) const;
8 string插入和删除操作
string& insert(int pos, const char* s);
string& insert(int pos, const string& str);
string& insert(int pos, int n, char c);
string& erase(int pos, int n = npos);
9 c++ 11 新特性
to_string() 转换数据类型为 string