1、string与字符数组转换
const char* c;
string s="1234";
c = s.c_str();
2、char转化为string
char c = 'a';
string s(1,c);
3、截取子串
std::string str="helloworld";
std::string str2 = str.substr (3,5); //首位index和长度
4、查找子串
std::string str ("There are two needles in this haystack with needles.");
std::string str2 ("needle");
std::size_t found = str.find(str2);//返回子串头的位置,rfind从后查找
5、替换子串
std::string str="this is a test string.";
std::string str2="n example";
str.replace(9,5,str2); // "this is an example string." 起始位 替换长度 待替换字符串
6、删除子串
str.erase (10,8); //起始为、长度