C++string 到char*的转换

1. data

string str="hellow world";

char *p =const_cast<char *>(str.data());

2. c_str

string str="hello world";

char *p=const_cast<char *>(str.c_str());

3. str.copy()

string str="hello world"

char p[40];

str.copy(p,str.length(),0);

p[str.length]='\0';

posted @ 2014-09-18 14:05  hana12169  阅读(190)  评论(0编辑  收藏  举报