代码
#include<iostream>
#include<string>
#include<stdio.h>
using namespace std;
int main()
{
//将字符数组中的数据传入字符串中
char test[50] = {};
gets_s(test);//用cin无法识别空格
string testString = test;
cout << testString<<endl;
//将字符串中的数据传入字符数组中
char test2[50];
for (int i = 0;i < strlen(test);i++)
{
test2[i] = testString[i];
cout << test2[i];
}
}
运行结果
![](https://img-blog.csdnimg.cn/img_convert/872f673e9e111175116d2a1de765cf03.png)