0


vscode配置的C++环境

1、下载并安装VScode

Visual Studio Code - Code Editing. Redefined

2、下载MinGW

在MinGW官网MinGW-w64 - for 32 and 64 bit Windows - Browse /mingw-w64/mingw-w64-release at SourceForge.net下载x86_64-posix-sjlj,解压到一个地方,如 D:,并复制其中 bin 目录的地址。

3、配置MinGW

3.1添加环境变量

点击 Path,点击编辑

点击新建,粘贴刚才复制的地址,点击确定。

3.2 Vscode配置

Vscode中搜索 C/C++,安装。

新建一个文件夹用于存放代码,并在该文件夹中创建一个 .vscode 文件夹,在 .vscode 文件夹中创建 c_cpp_properties.json、launch.json 和 tasks.json 文件,分别输入以下代码。

c_cpp_properties.json:

{
    "configurations": [
        {
          "name": "Win32",
          "includePath": ["${workspaceFolder}/**"],
          "defines": ["_DEBUG", "UNICODE", "_UNICODE"],
          "windowsSdkVersion": "10.0.17763.0",
          "compilerPath": "D:\\mingw64\\bin\\g++.exe",   /*修改成自己bin目录下的g++exe,这里的路径和电脑里复制的文件目录有一点不一样,这里是两个反斜杠\\*/
          "cStandard": "c11",
          "cppStandard": "c++17",
          "intelliSenseMode": "${default}"
        }
      ],
      "version": 4
}

launch.json:

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "g++.exe build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "miDebuggerPath": "D:\\mingw64\\bin\\gdb.exe",        /*修改成自己bin目录下的gdb.exe,这里的路径和电脑里复制的文件目录有一点不一样,这里是两个反斜杠\\*/
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "task g++"
        }
    ]
}

tasks.json:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558 
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
        "type": "shell",
        "label": "task g++",
        "command": "D:\\mingw64\\bin\\g++.exe",    /*修改成自己bin目录下的g++.exe,这里的路径和电脑里复制的文件目录有一点不一样,这里是两个反斜杠\\*/
        "args": [
            "-g",
            "${file}",
            "-o",
            "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "-I",
            "C:\\Users\\AAA\\Desktop\\nb\\VScode\\luogu",      /*修改成自己放c/c++项目的文件夹,这里的路径和电脑里复制的文件目录有一点不一样,这里是两个反斜杠\\*/
            "-std=c++17"
        ],
        "options": {
            "cwd": "D:\\mingw64\\bin"    /*修改成自己bin目录,这里的路径和电脑里复制的文件目录有一点不一样,这里是两个反斜杠\\*/
        },
        "problemMatcher":[
            "$gcc"
        ],
        "group": "build",
        
        }
    ]
}

3.3测试

运行一个 C++ 程序测试一下。

Test.cpp:

#include<iostream>
using namespace std;

int main() {

    cout << "Hello world" << endl;

    system("pause");

    return 0;
}

标签: vscode c++ ide

本文转载自: https://blog.csdn.net/T20151470/article/details/135304253
版权归原作者 老歌老听老掉牙 所有, 如有侵权,请联系我们删除。

“vscode配置的C++环境”的评论:

还没有评论