赞
踩
1.下载vscode
这个可以直接去官网下载
2.下载mingw64
下载mingw64就是下载C++的编译器g++和调试器gdb。这个也可以去官网下载,下载安装完成后去配置环境变量。
我将mingw64安装在D盘,配置环境如下:
这样就配置好了。
3.VScode安装插件
安装C/C++、C/C++ Compile Run两个插件
4.配置文件
新建文件夹cproject,在该文件夹下新建一个aa.cpp文件,代码如下,运行并调试。
# include <iostream>
using namespace std;
int main(){
cout<<"哈哈";
cout<<"hehe";
return 0;
}
1)运行aa.cpp
按下f6运行aa.cpp,运行结果如下:
若想弹出运行结果窗口,点击文件-->首选项-->设置,有如下页面,勾选
再按f6运行aa.cpp文件,出现以下cmd.exe窗口
2)按下f5调试aa.cpp文件
要调试c++文件,需要配置三个文件:task.json、launch.json和c_cpp_properties.json。
task.json文件如下:
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "task g++",
"command": "D:\\mingw64\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"-I",
"D://leecodeAlgorithm",
"-std=c++17"
],
"options": {
"cwd": "D:\\mingw64\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": "build"
},
{
"type": "cppbuild",
"label": "C/C++: g++.exe 生成活动文件",
"command": "D:\\mingw64\\bin\\g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "调试器生成的任务。"
}
]
}
launch.json文件如下:
{
"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++"
}
]
}
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
}
以上三个文件配置完成后,我们按f5调试aa.cpp文件,有以下成功界面:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。