C++ string相关学习

1、string转char*

①、string.c_str()返回一个以''结尾的字符数组;

②、string.data()仅返回字符串内容,而不含有结束符''。

2、char数组转string

char ch[]="hello world!";
string str(ch);
或者
string str = ch;

3、查找函数

std::string tStr = "123=321";
unsigned int equalSign = tStr.find("=", 0);//从位置0开始查找"="的位置
if(equalSign != std::string::npos){
    //  
}

4、获取子字符串

int equalSign = 10;
std::string key   = tStr.substr(0, equalSign); //返回从0到指定位置的字符串
std::string value = tStr.substr(equalSign+1);  //返回从指定位置到结尾的字符串

 5、转int

string a = "123";
const
int timeoutCount = atoi(a.c_str());



长风破浪会有时,直挂云帆济沧海!
可通过下方链接找到博主
https://www.cnblogs.com/judes/p/10875138.html
原文地址:https://www.cnblogs.com/judes/p/15034097.html