数据类型转换

string to char*

std::string str = "string";                 // 创建str字符串
char * cstr = new char[str.length() + 1];   // 创建char*字符串
strcpy(cstr, str.c_str());                  // 转换
delete [] cstr;

char* to string

char * cstr = "char string";                // 创建char*字符串
string str = cstr;                          // 转换
Last modification:March 3rd, 2020 at 10:15 pm
如果觉得我的文章对你有用,请随意赞赏