QT char*,char[],QString,string互相转换--草稿
------------------------
1. string转化为const char*
string s ="abc";
const char* c_s = s.c_str();
2. const char*转化string
可以直接赋值即可
const char* c_s ="abc";
string s(c_s);
3. string转化char*
string s ="abc";
char* c;
constint len = s.length();
c =newchar[len+1];
strcpy(c,s.c_str());
4. char*转string
char* c ="abc";
string s(c);
5. const char*转化char*
constchar* cpc ="abc";
char* pc =newchar[100];//足够长
strcpy(pc,cpc);
6. char*转化const char*
直接赋值即可
char* pc = "abc";
const char* cpc = pc;
参考:
https://blog.csdn.net/superrunner_wujin/article/details/103950512
https://blog.csdn.net/lg1259156776/article/details/52450395
赞 (0)