方法
1,下载官方C/C++拓展 2,将C/C++程序,项目装入文件夹 3,生成.vscode文件夹 4,在生成的.vscode文件夹中配置以下三个文件
setting.json
{
"C_Cpp.errorSquiggles": "Disabled",
"files.associations": {
"vector": "cpp"
}
}
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "compile",
"command": "g++",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
/*
如果需要是c语言也就是gcc将下面的command项由g++改为gcc
如果是多文件编译(即函数声明和函数定义分开,不懂的别乱改),需要将args列表中的"${file}"项修改为"${workspaceFolder}/*.cpp" ,多文件推荐用cmake
*/
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true, //这项决定了你的程序运行最后是输出在终端还是控制台
"MIMode": "gdb",
"miDebuggerPath": "gdb.exe",
"preLaunchTask": "compile",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}