版权声明:假装有个原创声明……虽然少许博文不属于完全原创,但也是自己辛辛苦苦总结的,转载请注明出处,感谢! https://blog.csdn.net/m0_37454852/article/details/86643319
只要在变量名后加.c_str()即可将string类型等效为C中的字符数组类型进行输入输出。
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
string str;
scanf("%s", str.c_str());
printf("%s", str.c_str());
return 0;
}