string s = "1234"; const char* c; c = s.c_str(); cout << c << endl; char cc[20]; strcpy(cc,s.c_str()); cout << cc << endl;
c_str就是将string类型的字符串转化成c语言字符串的指针常量(可读不可改变)。
可通过以上两种方式进行转化。

string s = "1234"; const char* c; c = s.c_str(); cout << c << endl; char cc[20]; strcpy(cc,s.c_str()); cout << cc << endl;
c_str就是将string类型的字符串转化成c语言字符串的指针常量(可读不可改变)。
可通过以上两种方式进行转化。