为什么VScode中c++的从控制台输入中文但是控制台不能进行输出,但是用cout输入的中文能够正常输出

为什么VScode中c++的从控制台输入中文但是控制台不能进行输出,但是用cout输入的中文能够正常输出,代码如下:

#include <iostream>
#include <cstring>
#include <algorithm>
#include <climits>
using namespace std;

int main()
{
    const int ArSize=20;
    char name[ArSize];
    char dessert[ArSize];
    
    cout << "Enter your name:\n";
    cin.getline(name,ArSize);
    cout << "Enter your favorite dessert:\n";
    cin.getline(dessert,ArSize);
    cout << "I have some delicious"<<dessert;
    cout << "for you,"<<name<<".\n";
    cout<<"诚信"<<endl;
    string a;
    cin>>a;
    cout<<a<<endl;
    return 0;
}

输出如下:

img

虽然在vscode里面不能正常输出,但是在dev c++中就可以正常输出。

char只能存ascii码存不了中文的,跟vscode没有关系

跟你的控制台字符集有关系,你的控制台字符集应该是utf-8,控制台需要和你的程序字符集一致才可以。