标签:
用str的c_str()方法或者data()方法均可,这个两个方法返回值为cong char *
string str = "hello"; const char *a = str.c_str(); const char *b = str.c_str();
const char*转换为 string,直接赋值即可
vs不让用strcpy,只能用strcpy_s代替
string str = "hello"; int str_len = str.length(); char *a = new char[str_len + 1]; strcpy_s(a, str_len + 1, str.c_str()); delete[] a;
直接赋值
const char *b = "hello"; char *a = new char[strlen(b) + 1]; strcpy_s(a, strlen(b) + 1, b); cout << a << endl; delete[] a;
直接赋值
char *a = "hello"; const char *b = a;
string char * const char *之间的互相转换
标签:
原文地址:http://www.cnblogs.com/raichen/p/5598477.html