右键点击文件夹,如果没有Open with Code
这个选项,在cmd/powershell,输入code .
,可以打开vscode
打开vscode,按ctrl+p打开快速命令框,输入以下命令后等待
ext install cpptools
下载插件C/C++、C++ Intellisense
第一,打开vscode,打开文件夹,新建一个文件夹,起名字,比如vscode,新建一个文件,起名字,比如test.cpp
#include <iostream> using namespace std; int main() { cout<<"Hello"; system("pause"); return 0; }
第二,按ctrl+shift+d,点击那个带着红点的齿轮,选择C++(GDB/LLDB)
然后会在工作目录下的生成一个launch.json
的启动配置文件,修改如下:
{ "version": "0.2.0", "configurations": [ { "name": "(gdb)Launch", "type":"cppdbg", "request": "launch", "program": "${workspaceRoot}/${fileBasenameNoExtension}.exe", "args": [], "stopAtEntry": false, "cwd": "${workspaceRoot}", "environment": [], "externalConsole": true, "MIMode": "gdb", "miDebuggerPath": "C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/gdb.exe", //miDebuggerPath是环境变量的路径64位的是gdb.exe "preLaunchTask": "g++", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ] } ] }
第三,再在文件夹中新建tasks.json
文件
{ "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 } } }
注:因为VS需要为每一个文件夹做单独配置,所以建议把.vscode
文件夹放到你常用的文件夹的顶层,这样就不用重复配置了
原文:https://www.cnblogs.com/GoldenEllipsis/p/11485017.html