首页 > 编程 > C++ > 正文

c++将string类型字符串转换成char *

2019-11-06 07:21:41
字体:
来源:转载
供稿:网友

例子:

利用strcpy和c_str();

#include<iostream>

#include<string>using namespace std;int main(){string str="i love you";char ch[str.length()];strcpy(ch,str.c_str());cout<<ch<<endl;cout<<ch[3]<<endl;

}

运行结果:

i love youo请按任意键继续. . .


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选