char* 转 string
char* str = "oh cool";
string new_str = str;
string 转 char*
使用 c_str() 函数:
string str="oh cool";
const char* p = str.c_str();
c_str() 函数返回一个只读不可写的指针,若需修改字符串,需要使用拷贝函数 strcpy():
string str="oh cool";
char new_str[10];
strcpy(new_str, str.c_str());