C language printf Chinese garbled solution in vs code

sequence

        1. Commonly used functions in window.h == " SetConsoleOutputCP function - Windows Console | Microsoft Learn

        2. SetConsoleOutputCP Reference == "   Console Code Page - Windows Console | Microsoft Learn

 The following code is printed as garbled characters, as shown in the figure

#include <stdio.h>
int x;
int y;
int addTwoNum(){
    extern int x;
    extern int y;
    x=1;
    y=2;
    return x+y;
}
int main(){
    int result;
    result =addTwoNum();
    printf("result 为:%d",result);
    return 0;
}

Solution program, import standard library

#include <windows.h>

 Call the api to make the output result in utf-8 encoding format

SetConsoleOutputCP(65001);

The effect is as shown in the figure

Guess you like

Origin blog.csdn.net/xuelang532777032/article/details/129958707