vscode的配置

win10 vscode的安装与配置

1.vscode的安装

请到官网下载安装包: https://code.visualstudio.com/

运行安装程序时请勾选添加到PATH

2.g++的安装

下载地址: https://sourceforge.net/projects/mingw-w64/files/

下滑选择online包 MinGW-W64-install.exe 点击运行安装程序,点击next 将Architecture改为x86_64 一路next,等待下载安装

3.环境变量的配置

右键单击此电脑,选择属性 点击高级系统设置 点击环境变量 在系统变量和用户变量的PATH中添加MinGW中bin的路径 上述路径一般是:

C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin

4.C语言插件的安装

按CTRL+Shift+X 搜索C/C++,点击install

5.json文件的配置

打开一个文件夹 新建文件夹.vscode,并在其中新建三个文件

launch.json

setting.json

tasks.json

写入内容

launch.json

{
  "version": "0.2.0",
  "configurations": [
      {
          "name": "(gdb) Launch",
          "type": "cppdbg",
          "request": "launch",
          "targetArchitecture": "x86",
          "program": "C:\\Windows\\system32\\cmd.exe",
          "args": ["/C","${fileDirname}\\${fileBasenameNoExtension}.exe","&","pause"],
          "miDebuggerPath": "C:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\bin\\gdb.exe",//此处应为你的路径
          "stopAtEntry": false,
          "cwd": "${fileDirname}",
          "externalConsole": true,
          "preLaunchTask": "g++"
      }
  ]
}

setting.json

{
  "files.associations": {
      "vector": "cpp",
      "random": "cpp",
      "iostream": "cpp",
      "array": "cpp",
      "atomic": "cpp",
      "*.tcc": "cpp",
      "bitset": "cpp",
      "cctype": "cpp",
      "cfenv": "cpp",
      "charconv": "cpp",
      "chrono": "cpp",
      "cinttypes": "cpp",
      "clocale": "cpp",
      "cmath": "cpp",
      "codecvt": "cpp",
      "complex": "cpp",
      "condition_variable": "cpp",
      "csetjmp": "cpp",
      "csignal": "cpp",
      "cstdarg": "cpp",
      "cstddef": "cpp",
      "cstdint": "cpp",
      "cstdio": "cpp",
      "cstdlib": "cpp",
      "cstring": "cpp",
      "ctime": "cpp",
      "cuchar": "cpp",
      "cwchar": "cpp",
      "cwctype": "cpp",
      "deque": "cpp",
      "forward_list": "cpp",
      "list": "cpp",
      "unordered_map": "cpp",
      "unordered_set": "cpp",
      "exception": "cpp",
      "algorithm": "cpp",
      "functional": "cpp",
      "iterator": "cpp",
      "map": "cpp",
      "memory": "cpp",
      "memory_resource": "cpp",
      "numeric": "cpp",
      "optional": "cpp",
      "ratio": "cpp",
      "regex": "cpp",
      "set": "cpp",
      "string": "cpp",
      "string_view": "cpp",
      "system_error": "cpp",
      "tuple": "cpp",
      "type_traits": "cpp",
      "utility": "cpp",
      "fstream": "cpp",
      "future": "cpp",
      "initializer_list": "cpp",
      "iomanip": "cpp",
      "iosfwd": "cpp",
      "istream": "cpp",
      "limits": "cpp",
      "mutex": "cpp",
      "new": "cpp",
      "ostream": "cpp",
      "scoped_allocator": "cpp",
      "shared_mutex": "cpp",
      "sstream": "cpp",
      "stdexcept": "cpp",
      "streambuf": "cpp",
      "thread": "cpp",
      "typeindex": "cpp",
      "typeinfo": "cpp",
      "valarray": "cpp"
  },
  "editor.fontFamily": "Consolas, 'Fira code', monospace",
  "C_Cpp.errorSquiggles": "Disabled"
}

tasks.json

{
"version": "2.0.0",
"command": "g++",
"type": "shell",
"presentation": {
  "echo": false,
  "reveal": "always",
  "focus": false,
  "panel": "shared",
  "showReuseMessage": false,
  "clear": false
},
"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
  }
}
}

6.测试是否成功

新建test.cpp 粘贴以下代码

#include<stdio.h>
int main(){
  printf("hello world");
  return 0;
}

点击左边的三角

点击左边的绿色三角(或者是运行和调试然后选择GDB)

观察输出

7.界面美化

推荐几个插件

1.Chinese(simplified)language //汉化插件

2.Bracket Pair Colorozer //方便配对括号

3.vscode-icons //便于区分不同文件

4.Markdown Preview Enhanced //边写边预览markdown

5.Markdown PDF //markdown转PDF

posted on 2021-07-24 17:30  EwinLit  阅读(181)  评论(0)    收藏  举报