string和char*

来源:互联网 发布:企业it解决方案 编辑:程序博客网 时间:2024/06/04 19:35

string转const char*

string s = "hello furong.";const char *c = s.c_str();

string转char*
string -> const char* -> char*

string s = "hello furong.";char *c = (char *)malloc(s.length());memset(c, 0, s.length());memcpy(c, s.c_str(), s.length());

char*转string
直接赋值

const char *c = "hello furong.";string s = c;