C/C++|Introduction to Internet of Things Development + Project Combat|C Language Basics|C Compilation Environment Configuration in VSCode (MinGW+gcc)|cpptools|Code Runner|encoding-Study Notes (1)


Excerpt from: Wheat Academy - C Language Programming and Quick Start

C compilation environment configuration in VSCode (MinGW+gcc)

Operating system: win10 professional edition, 64-bit

Software and tools to be installed

Visual Studio Code
MinGW-w64 - for 32 and 64 bit Windows

1. Install VSCode

Download Visual Studio Code
Free and built on open source. Integrated Git, debugging and extensions.
insert image description here

2. Install the C/C++ plugin

Start vscode and install the plug-in:
Method 1: Use the shortcut key ctrl+shift+x to enter the extension interface, then search for the "cpptools" plug-in and install it Method
2: Use the shortcut key ctrl+shift+p to open the command box and enter ext install cpptools):
insert image description here
It is recommended to use the code execution plug-in:
Search for Code Runner in the Code Runner extension interface, install it, and see the figure after completion:
insert image description here

execute code

After installing Code Runner, run your code:
keyboard shortcut Ctrl+Alt+N
shortcut F1 to bring up the command panel, then enter Run Code
in the editing area, right-click to select Run Code
in the file manager on the left, right-click to select Run
The small running triangle button in the upper right corner of Code

Stop the code from running

Keyboard shortcut Ctrl+Alt+M
shortcut F1 to bring up the command panel, then enter Stop Code Run
in the Output Channel, right click and select Stop Code Run

Code Runner configuration method

"File" - "Preferences" - "Settings", you can also press Ctrl+ to directly open the setting panel, and enter: code-runner.executorMap in the search box. Refer to the original text
link: runner.executorMap analysis
$workspaceRoot: absolute path of the workspace. d:\CodeProject
$dir: the absolute path of the folder where the file to be run is located, with \ at the end. d:\CodeProject\python
$dirWithoutTrailingSlash: The absolute path of the folder where the file to be run is located, without \ at the end. d:\CodeProject\python
$fileName: just the name of the file, with a suffix. Student.py
$fileNameWithoutExt: Just the name of the file, without the suffix. Student
full File Name: Equivalent to fullFileName: Equivalentf u llF i l e N am e : Equivalent to dir+$fileName. d:\CodeProject\python\Student.py

3. Download and install MinGW:

Download MinGW-w64 - for 32 and 64 bit Windows: https://sourceforge.net/projects/mingw-w64/files/,
select MinGW-W64-install.exe (note that your computer is 32-bit or 64-bit):
Download After the installation is complete, if "cannot download repository.txt" appears during the installation process, right click and run as an administrator. If an error message still appears, refer to: https://www.cnblogs.com/zhicungaoyuan-mingzhi/p/12804210. htmlWhen
Anaconda3 is installed on this machine, MinGW already exists. You can directly configure gcc in the path, and
add the path F:\Anaconda3\pkgs\mingw-4.7-1\MinGW\bin\gcc-nm.exe to the system path.

4. Verify

Open the cmd command prompt, enter the gcc -v command to check whether there is the following information, if there is, it is successful:
insert image description here

5. Execute the program

Test code:

#include<stdio.h>
int main()
{
    
    
    printf("hello world,你好!\n");
    return 0;
}

Results of the:insert image description here

TIPS: The solution to the garbled characters in the vscode output panel

The output panel of vscode uses UTF8 character encoding by default. The character encoding of the terminal panel is the same as that of cmd.exe, and the default is to use GBK character encoding, so if you use GBK encoding input, if you configure the terminal output results during debugging, there will be no garbled characters.
insert image description here
And if it is configured to output the running results in the output panel, there will be garbled characters:
The runcode plugin outputs program running results in the output panel by default
Solution:
1), configure the output of the runcode plug-in to output in the terminalinsert image description here
2), modify the character encoding of cmd.exe to UTF8
1, enter the chcp command and press Enter , will output the result in the figure, 936 means gbk encoding;
2. Then enter chcp 65001 (65001 represents utf-8 encoding) in the window, and press Enter, you can see that the default encoding of the window is utf-8 encoding. Valid temporarily.
For the system-level modification method, please refer to the blog post: How to modify the default encoding of the cmd console to utf-8 and display Chinese characters correctly
3), the editor encoding setting encoding
insert image description here

Guess you like

Origin blog.csdn.net/Medlar_CN/article/details/130058483