1.cin中文乱码的解决
2.代码实践
# include "iostream"
# include "windows.h"
using namespace std;
int main()
{
SetConsoleOutputCP(CP_UTF8);
string str;
cin >> str;
cout << str << endl;
return 0;
}
注意,勾选之后以后也不需要再加 SetConsoleOutputCP(CP_UTF8);了
3.总结
4.练习题
# include "iostream"
using namespace std;
int main()
{
string name;
double height;
int age;
cout << "请输入您的姓名:" << endl;
cin >> name;
cout << "请输入您的身高(CM):" << endl;
cin >> height;
cout << "请输入您的年龄:" << endl;
cin >> age;
cout << "-------------" << endl;
cout << "信息输入完成,您的信息如下:\n姓名:" + name + "\n身高:" + to_string(height) + "cm\n年龄:" + to_string(age) << endl;
return 0;
}