标签:
1. string转const char*
1 string str ="abc"; 2 const char* charArr = str.c_str();
2. const char*转string
1 const char* charArr = "abc"; 2 string str(charArr);
3. string转char*
1 string str ="abc"; 2 char* charArr; 3 const int len = str.length(); 4 charArr =new char[len+1]; 5 strcpy(charArr, str.c_str());
4. char*转string
1 char* charArr ="abc"; 2 string str(c);
5. const char*转char*
1 const char* charArr1 ="abc"; 2 char* charArr2 = new char[100]; // 足够长 3 strcpy(charArr1, charArr2)
[基础-001]C++字符串转换(char*,const char*,string)
标签:
原文地址:http://www.cnblogs.com/superdo/p/4402232.html