版本比较
[笔记][STL]string
正文
增加 9 行删除 9 行
68 行未改动6970717273747576737475767778798053 行未改动1341351361371381381391401411421431441451451461471481491491501511521532 行未改动1561571581591601601611621631631641651661672 行未改动68 行未改动getline(cin,name,'#')//以'#'结束```### 判断子串```cppif(a.find(b) == string::npos) cout << "not found\n";//b是a的子串 else cout <<"found\n";//b不是a的子串 if(a.find(b) == string::npos) cout << "not found\n";//b是a的子串else cout <<"found\n";//b不是a的子串```## string 逆天### 查找```cpp53 行未改动#### 插入 insert```cppstring str="frontbehind";string s="插入部分";str.insert(5,s);//第五个字符后插入 str.insert(5,s);//第五个字符后插入cout<<str<<endl;```结果:front插入部分behind#### 删除 erase```cppstring str1="frontbehind";str1.erase(5);//第五个字符后全部删除 str1.erase(5);//第五个字符后全部删除cout<<str1<<endl;
string str2="frontmiddlebehind";str2.erase(5,6);//第五个字符后删除6个字符 str2.erase(5,6);//第五个字符后删除6个字符cout<<str2<<endl;```结果:```2 行未改动```#### 截取 substr```cppstring str1="frontbehind";cout<<str1.substr(5)<<endl;//第五个字符后截取所有字符 cout<<str1.substr(5)<<endl;//第五个字符后截取所有字符
string str2="frontmiddlebehind";cout<<str2.substr(5,6)<<endl;//第五个字符后截取6个字符 cout<<str2.substr(5,6)<<endl;//第五个字符后截取6个字符```结果:```behind2 行未改动