string和char*

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;
posted @ 2017-05-18 11:45  thomas_blog  阅读(81)  评论(0编辑  收藏  举报