BUG: VS Code C++輸出中文亂碼
環境
Windows 11
VS Code 編輯器
詳情
在Windows 使用 cout 函數輸出中文時出現亂碼
問題的原因在cmd的顯示編碼和c++程序編碼的不同。cmd默認的是gbk編碼,而VS Code 軟件的CMD終端默認是utf-8編碼,因而在輸出中文文本時會出現亂碼。
解決方法
在cout
語句之前添加 chcp 65001
代碼
#include <iostream>
#include <limits>
using namespace std;int main()
{system("chcp 65001");cout << "int 類型占用內容大小 " << sizeof(int) << endl;cout << "int 最大值 " << (numeric_limits<int>::max)() << endl;cout << "int 最小值 " << (numeric_limits<int>::min)() << endl;return 0;
}
參考
https://www.cnblogs.com/roadwide/p/10533594.html