Configure vscode to write C or C++ programs, and output the program on the external console and solve the problem of Chinese garbled characters! ! !
1. Click Extensions and add the plug-ins required for C language (click Install, and after the installation is complete, click the Set icon to install another version. Be sure to install version 1.8.4. This version can automatically generate the configuration files required for code running), After completion, reload or close vscode and reopen it.
2. Download and install the compiler MinGW and system variable configuration
https://sourceforge.net/projects/mingw-w64/files/
参数选择:
①64位电脑选择x8664;32位电脑选择686
②写的C语言程序运行在windows下选择win32;
运行在其它操作系统下选择posix(这是一个协议,windows.不遵循)
③64位电脑,seh比较新但不支持32位;sjj支持32位稳定性好,
推荐选择seh,因为在安装程序中默认就是选seh。
④32位电脑,dwarf性能更优但不支持64位。
After downloading to local area, unzip it to any location (do not include Chinese characters in the path), copy the bin directory path to configure system variables
Enter the advanced system settings, open environment variables, find path in system variables, and paste the copied path into the new variable
Then open the command line and enter gcc -v. If a lot of codes appear, it means the environment configuration is successful. If it prompts that this is an illegal command, it means the configuration failed.
3. After the installation is complete, use vscode to open any folder to save the code (it is best not to have Chinese characters in the path and an error may be reported)
Create a new file in the folder with .c as the suffix
Enter the following sample code
#include<stdio.h>
int main(void){
printf("Hello World!");
printf("你好啊!");
system("pause");//可以在外部控制台打开
return 0;
}
Then press F5 or click Run to run the code (debugging or not)
After clicking Run, click the first C++ [GDB/LLDB] in the pop-up window
After clicking, select the local compiler in the pop-up window.
Then you will find that a .vscode folder will be automatically generated in the folder, with two json files in it. The debugging console below will output the following content, and print out the content to be output in the code in the terminal.