码迷,mamicode.com
首页 > 编程语言 > 详细

C++string 到char*的转换

时间:2014-09-18 14:45:34      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:ar   sp   on   c   c++   r   bs   as   har   

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

C++string 到char*的转换

标签:ar   sp   on   c   c++   r   bs   as   har   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!