vscode configure c++ for Windows 10

After reading my other article, you can understand what this one is.

In the first step, I need to create several files for my project file,
Insert picture description here
four json files, whether or not the setting is not affected. The main ones are task.json and launch.json

(1) First create a main.cpp file, type in the program test

#include<iostream>
using namespace std;

int main()
{
    
    
    cout<<"hello c++"<<endl;
   system("pause"); 
}   

Insert picture description here

(2) Then click on the little bug

Insert picture description here

(3) Select the option of Windows to create launch.json document and task.json document

Then just overwrite the
launch.json file with the following code. Pay
attention to this sentence, the path of this sentence is the location where you downloaded the gdb.exe of MinGW.

“miDebuggerPath”: “C:/Users/sms/Documents/MinGW/bin/gdb.exe”,

{
    
    
"version": "0.2.0",
    "configurations": [
        {
    
    
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceRoot}/${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "miDebuggerPath": "C:/Users/sms/Documents/MinGW/bin/gdb.exe",
            "preLaunchTask": "g++",
            "setupCommands": [
                {
    
    
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        
        },
    ]
}
        

(4) task.json file

{
    
    
 
    "version": "2.0.0",
    "command": "g++",
    "args": [
        "-g",
        "${file}",
        "-o",
        "${fileBasenameNoExtension}.exe"
        ],    // 编译命令参数
    "problemMatcher": {
    
    
        "owner": "cpp",
        "fileLocation": ["relative", "${workspaceRoot}"],
        "pattern": {
    
    
            "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
            "file": 1,
            "line": 2,
            "column": 3,
            "severity": 4,
            "message": 5
        }
    }
}

(5) Finally, c_cpp_properties.json (created by Ctrl+Shift+P):

The same sentence is the same path,

“compilerPath”: “C:\Users\sms\Documents\MinGW\bin\gdb.exe”,

{
    
    
    "configurations": [
        {
    
    
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "C:\\Users\\sms\\Documents\\MinGW\\bin\\gdb.exe",
            "cStandard": "gnu11",
            "cppStandard": "gnu++17",
            "intelliSenseMode": "windows-gcc-x64"
        }
    ],
    "version": 4
}

Insert picture description here

Can

Guess you like

Origin blog.csdn.net/Msyusheng/article/details/113866261