安装mingw并配置环境变量
安装C/C++插件
创建一个测试文件Helloworld.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| #include <iostream> #include <vector> #include <string>
using namespace std;
int main() { vector<string> msg {"Hello", "C++", "World", "from", "VS Code", "and the C++ extension!"};
for (const string& word : msg) { cout << word << " "; } cout << endl; }
|
环境配置
搜索C/C++
编译器路径选择mingw的安装路径即可
设置完成后会生成c_cpp_properties.json
文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| { "configurations": [ { "name": "Win32", "includePath": [ "${workspaceFolder}/**" ], "defines": [ "_DEBUG", "UNICODE", "_UNICODE" ], "windowsSdkVersion": "10.0.18362.0", "compilerPath": "D:/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin/g++.exe", "cStandard": "c17", "cppStandard": "c++17", "intelliSenseMode": "gcc-x64" } ], "version": 4 }
|
配置构建任务
选择后会生成tasks.json
配置调试设置
在菜单栏选择Run–>Start Debugging,然后选择C++(GDB/LLDB)