VSCode install and configure the C ++ programming environment

First, download and install VSCode

(1) from https://code.visualstudio.com/ download and install the latest version of VSCode.
Here Insert Picture Description
(2) During the installation, to check the "needs to be added to the PATH" in.
Here Insert Picture Description

Second, install MinGW

VSCode itself is just a text editor, you can write C / C ++ or other code languages, but can not compile and debug. So also you need to install the appropriate language compiler and debugger.

MinGW contains a C language compiler gcc.exe, C ++ compiler g ++. Exe, C / C ++ debugger gdb.exe / gdb32.exe.

If no MinGW, can be downloaded and installed. If the computer has a DevC ++ or CodeBlocks installed, because DevC ++ or CodeBlocks already comes with MinGW (or MinGW64), you do not need to be installed.
Here Insert Picture Description

Third, add the compiler and debugger path to the Path environment variable

. gcc.exe, g ++ exe, gdb.exe other tools located MinGW64 \ bin \ in:
Here Insert Picture Description
it needs to be MinGW64 \ bin directory to global variables.
(1) Right-click "This Computer" -> "Properties" -> "Advanced System Settings" -> "Environment Variables" editing "system variables" in the "path", the add MinGW64 \ bin path:
Here Insert Picture Description
(2) write-off user or restart the computer, open cmd command line window, enter the command echo% path%, see MinGW64 \ bin in diameter has already been included in the path.
Here Insert Picture Description
(3) adding MinGW64 \ bin to the Path, some tools can execute instructions MinGW64 \ bin in the path of any computer. Such as c ++ compiler command g ++ exe.:
Here Insert Picture Description

Fourth, add support C ++ syntax

(1) Create a special place VS workspace file folder, for example, I built a VSC ++ desktop folder. Click VS left column of the first icon "Explorer" in the "Open Folder", open VSC ++ directory.
Here Insert Picture Description
(2) Click on the right side of the VSC ++ New File icon, a new cpp file, such as hello.cpp. Note that this extension does not generate automatically, manually write.
Here Insert Picture Description
(3) written on behalf of the hello.cpp found keywords do not automatically think of. Description at this time VSC ++ does not support C ++ syntax.
Here Insert Picture Description
(4) click on the left VSCode "App Store (Extensions)", search for C / C ++ syntax plugins, and install
Here Insert Picture Description
(5) After completing the installation, re-write the code in hello.cpp found VS supports C ++ syntax, including key word association, syntax highlighting and so on.
Here Insert Picture Description

Fifth, compile and run the function

After writing a C ++ program, I found not compile and run the program. Code Runner case need to install the plug.
(1) Search Code Runner in VS app store and install it.
Here Insert Picture Description
(2) After Bahrain, we found more than a right triangle button. This button is used to run the code.
Here Insert Picture Description
(3) Back hello.cpp, Run Code button click the upper-right or right-code region, the pop-up menu, select the first button Run Code, can see the results.
Here Insert Picture Description

Six, C ++ debugging features

Then give VSCode plus debugging C ++ code functions.
(1) on the right side of the VSC ++ in VSCode Explorer, click the second button to add a sub-folder named .vscode, note the name of a little number. .vscode inside to store configuration files such as launch.json and tasks.json.
Here Insert Picture Description
(2) Right-click .vscode, in this new directory launch.json and tasks.json.
Here Insert Picture Description
(3) the content launch.json as follows:

{
    "version": "0.2.0",
    "configurations": [

        {
            "name": "C/C++",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "miDebuggerPath": "C:\\Program Files (x86)\\Dev-Cpp\\MinGW64\\bin\\gdb.exe",
            "preLaunchTask": "g++",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
        },
    ]
}

Note that this miDebuggerPath parameter value is the full path of the debugger gdb.exe. Also, do not use gdb32.exe, otherwise it will error when debugging.

(4) content in tasks.json as follows:

{
    "version": "2.0.0",
    "command": "g++",
    "args": [
        "-g",
        "${file}",
        "-o",
        "${fileDirname}/${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
        }
    },
    "group": {
        "kind": "build",
        "isDefault": true
    }
}

(5) Click VSCode the left toolbar "Run and Debug" button can be found more than a green button on top. Or click on the top of the "Debug" button, find the pop-up submenu much "Start Debugging" button.
Here Insert Picture Description
(6) Click the green triangle button or Start Debugging menu, you can debug.
Here Insert Picture Description

Seven, setting data input function

Just packed VSCode encountered cin statement, can not enter data. You need to be set.
(1) Select "File" -> "Preference" -> "Setting" -> "User" -> "Extensions" -> "Run Code Configuration", check the "Run in Terminal" right.
Here Insert Picture Description
(2) Run the code in the input data can be found at the bottom of the code region Terminal
Here Insert Picture Description

Eight, change the subject

(1) Select the top left corner of the "File" -> "Preference" -> "Setting" -> "User" -> "Workbench" -> "Apperance", you can change the theme in the Color Theme. The default theme Default Dark +, if the change Default Light +, will become white, as shown below:
Here Insert Picture Description
(2) If additional messages that can be extended to store search "Theme" download and install more themes.
Here Insert Picture Description

Nine, add localization functions

(1) Search Simplified Chinese language pack expand the store and install it.
Here Insert Picture Description
(2) Bahrain restart VSCode to see the name became a Chinese menu.
Here Insert Picture Description

Ten, menu language switching

Language menu display can be switched premise is installed language pack. The default display only English. If Chinese language pack through the (seventh step as indicated above) is mounted, to switch between Chinese and English, the steps of:
(1) Click the "Settings" button the lower left corner VSCode  "command panel", at the command panel input box enter language,
Here Insert Picture Description
(2) select "Configure Display language", in the pop-language options, select the appropriate language, en for English, zh-cn Chinese representatives. After selecting the restart VSCode, you can find the interface language has changed.
Here Insert Picture Description

Learn Olympiad please add QQ group or micro-channel 307 591 841 581 357 582

Published 407 original articles · won praise 408 · Views 2.15 million +

Guess you like

Origin blog.csdn.net/haishu_zheng/article/details/104303088