string 转 const char

std::string str = "string"; const char *cstr = str.c_str();

Note that it returns a const char *; you aren't allowed to change the C-style string returned byc_str(). If you want to process it you'll have to copy it first:

std::string str = "string"; char *cstr = new char[str.length() + 1]; strcpy(cstr, str.c_str()); // do stuff delete [] cstr;

你可能感兴趣的:(string 转 const char)