C++string 到char*的转换

时间:2014-09-18 14:45:34   收藏:0   阅读:273

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‘;

原文:http://www.cnblogs.com/hana12169/p/3979127.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!