赞
踩
vscode从配置到安装,请参考博客:https://blog.csdn.net/didi_ya/article/details/106931500
C/C++插件是必要的。
可选插件:Code Runner
具体安装步骤可参考博客:https://blog.csdn.net/didi_ya/article/details/111240502
1.新建一个文件夹(我这里在E盘中新建了一个code,里面再新建了一个C++文件夹)
2.进入vscode,文件–>新建文件夹
3.新建一个名为.vscode的文件夹
4.创建一个launch.json启动配置文件
复制如下命令:
{ "version": "0.2.0", "configurations": [ { "name": "C++ Launch (GDB)", "type": "cppdbg", "request": "launch", "targetArchitecture": "x86", "program": "${workspaceRoot}\\${fileBasename}.exe", "miDebuggerPath":"D:\\mingw64\\bin\\gdb.exe", "args": [], "stopAtEntry": false, "cwd": "${workspaceRoot}", "externalConsole": true, "preLaunchTask": "g++" } ] }
【注意】:这里根据自己的文件安装目录进行更改:
5.创建一个tasks.json的配置文件
复制如下命令:
{ "version": "0.1.0", "command": "g++", "args": ["-g","-std=c++11","${file}","-o","${workspaceRoot}\\${fileBasename}.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.创建一个c_cpp_properties.json文件
并复制如下命令:
{ "configurations": [ { "name": "Win32", "includePath": [ "${workspaceRoot}", "D:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++", "D:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32", "D:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward", "D:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include", "D:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/tr1", "D:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include" ], "defines": [ "_DEBUG", "UNICODE", "__GNUC__=6", "__cdecl=__attribute__((__cdecl__))" ], "intelliSenseMode": "msvc-x64", "browse": { "path": [ "${workspaceRoot}", "D:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++", "D:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32", "D:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward", "D:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include", "D:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/tr1", "D:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include" ] }, "limitSymbolsToIncludedHeaders": true, "databaseFilename": "" } ], "version": 3 }
【注意】:这里同样根据自己的文件安装目录进行更改:
7.新建一个test.cpp文件,并点击左侧的调试按钮
#include <iostream>
#include <windows.h>
#include <vector>
using namespace std;
int main() {
cout << "hi, I love you!" << endl;
vector<int> a;
a.push_back(5);
cout << a[0] << endl;
system("pause");
return 0;
}
然后,我们点击左侧的运行按钮,
得到如下结果:
设置断点:
运行结果:
ok,大功告成,可以运行了。
如果帮助到你,记得点个赞呦~
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。