c++字符串和字符数组互相转
2019-12-19 本文已影响0人
送分童子笑嘻嘻
void main()
{
//字符串转字符数组
string name = "ddddd";
char buf[] = {0};
strcpy(buf , name.c_str());//字符串转字符数组,使用strcpy
cout << name.c_str() << endl;//name.c_str()将字符串转换成字符数组
cout << buf << endl;
//字符数组转字符串
char buf1[]= "xxxxxx";
string name1;
name1 = buf1;
cout << name1 << endl;
}