VS Code C/C++ environment construction

VS Code C/C++ environment construction

installation

Download vscode from the official website, https://code.visualstudio.com/,
click to install, follow the steps, and tick all the choices.
Download mingw64 official website: https://sourseforge.net/projects/mingw-w64/
after downloading , Unzip, put the mingw64 folder under the C drive
Insert picture description here

Environment variable

Insert picture description here
Modify environment variables: advanced system settings-advanced-environment variables-system variables-path-new-new-copy the bin folder path of mingw64 into it and click OK.
Enter gdb in the command prompt window, and the result as shown in the figure appears, indicating that the compiler is installed successfully
Insert picture description here

Install c++/c plugin

Insert picture description here

Modify the debug file

Insert picture description here
Create a new folder vs code, create a new hello.cpp file in the folder, run it, click *C++(GDB/LLDB)*, the vscode folder and launch.json will appear, shift+ctrl+p will bring up the window and enter tasks to bring up tasks. json file
Insert picture description here

Insert picture description here

task

{
    
    
    "tasks": [
        {
    
    
            "type": "cppbuild",
            "label": "C/C++: g++.exe build active file",  //要与launch.json中的prelaunchtask保持一致
            "command": "g++",   //编译器
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe",
                "-std=c++17"   //添加最新的c++标准
            ],
            "options": {
    
    
                "cwd": "C:\\mingw64\\bin"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
    
    
                "kind": "test",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        }
    ],
    "version": "2.0.0"
}

launch

{
    
    
    // 使用 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": "C:\\mingw64\\bin",
            "environment": [],
            "externalConsole": true,  //使用窗口输入就用true,用调试控制台就是false
            "internalConsoleOptions": "neverOpen", //补一行,不开启调试控制台
            "MIMode": "gdb",
            "miDebuggerPath": "C:\\mingw64\\bin\\gdb.exe",
            "setupCommands": [
                {
    
    
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: g++.exe build active file"
        }
    ]
}

Modify the code formatting format

Modify the clang_format_style to your habit,
Insert picture description here
modify the C/C++ standard
Insert picture description here

Guess you like

Origin blog.csdn.net/qq_40602655/article/details/111577613