Windows configuration vscode environment

Reference original text:

https://zhuanlan.zhihu.com/p/643934671

https://blog.csdn.net/qq_50677040/article/details/131445460

1. Download vscode

Official website download link:https://code.visualstudio.com/Download

2. Download the compiler MinGW

(1) Download address:https://sourceforge.net/projects/mingw-w64/files/

(2) After downloading, unzip it to your target location, and then configure the environment variables

Right-click "This PC" -> "Properties", find "Advanced System Settings" -> "Environment Variables", select "path", click "Edit" -> "New", and put the unzipped bin of mingw64 Add the path and confirm it all the way.

Start the cmd console to check and verify whether the configuration is correct: enter gcc -v, g++ -v to check the version information

(3) Install vscode extension

Install the Chinese language system and c/c++. After switching to the Chinese system, you need to restart vscode to take effect.

 Create a new folder and click "Open Folder" (you can also click on the welcome interface)

 Click to create .cpp file

Add the following code:

#include <iostream>
using namespace std;
int main()
{
    cout << "hello world" << endl;
    return 0;
}

Down Ctrl+Shift+P Adjustment face plate, import C/C++Edit placement (UI),Selection


 At this time, .vscode/c_cpp_properties.json 

Configure build tasks

Return to the resource manager interface, Ctrl+Shift+P  Bring up the panel, enter  tasks , select Task: Configure default build task, and then select C/C++:g++.exe Build Activity File a>, as shown below. 

 

 At this time, the .vscode folder is generated tasks.json file

Configure debugging settings

Return to the main.cpp interface, press Ctrl+Shift+P  to bring up the panel, enter  debug, select Debug: Start debugging, then select  C++ ( GDB/LLDB)

 

Click to create launch.json file, and then select C++ (GDB/LLDB)  

A launch.json file will be generated

Modify the launch.json file to the following: 

Note: miDebuggerPath: is the path of gdb.exe under the downloaded mingw64 path

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "g++.exe - 生成和调试活动文件",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "miDebuggerPath": "D:/Software/Mingw/mingw64/bin/gdb.exe",
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: g++.exe 生成活动文件"
        }
    ]
}

Verify feasibility

Click on the main.cpp file and press F5 or the debug button in the upper right corner to run

It flashes by without a break point. Put a breakpoint at the return 0; sentence, run it again, and you will see output on the console. Click Continue to stop the program.

You can also add the following system("pause"); in the code

END

Guess you like

Origin blog.csdn.net/WenHuiJun_/article/details/133132335