{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceRoot}"
],
"defines": [
"_DEBUG",
"UNICODE",
"__GNUC__=6",
"__cdecl=__attribute__((__cdecl__))"
],
"intelliSenseMode": "msvc-x64",
"browse": {
"path": [
"${workspaceRoot}"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
},
"cStandard": "c11",
"cppStandard": "c++17"
}
],
"version": 4
}
由于我本机Qt的缘故,所以我要重新配置下"includePath"(以解决cout被识别为未定义标志符这个错误)添加mingw及头文件所在的路径
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceRoot}",
"D:/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++",
"D:\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\8.1.0\\include\\c++\\x86_64-w64-mingw32",
"D:\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\8.1.0\\include\\c++\backward",
"D:\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\8.1.0\\include",
"D:\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\8.1.0\\include\\c++\tr1",
"D:\\mingw64\\x86_64-w64-mingw32\\include"
],
"defines": [
"_DEBUG",
"UNICODE",
"__GNUC__=6",
"__cdecl=__attribute__((__cdecl__))"
],
"intelliSenseMode": "msvc-x64",
"browse": {
"path": [
"${workspaceRoot}"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
},
"cStandard": "c11",
"cppStandard": "c++17"
}
],
"version": 4
}
3.配置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, //若参数为true,输出结果就会在cmd窗口中显示,若为false,输入输出则显示在终端
"MIMode": "gdb",
"miDebuggerPath": "D:\\mingw64\\bin\\gdb.exe", //只需将本行的路经改为自己mingw所在的路经,以我的为例,将斜线改为双斜线
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "g++.exe build active file"
}
]
}
4.最后是tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "g++.exe build active file",
"command": "D:\\mingw64\\bin\\g++.exe", //将本行的路经改为自己mingw所在的路经,以我的为例,将斜线改为双斜线
"args": ["-g", "${file}", "-o", "${fileDirname}\\${fileBasenameNoExtension}.exe"],
"options": {
"cwd": "D:\\mingw64\\bin" //将本行的路经改为自己mingw所在的路经,只需要到bin目录即可
},
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
问题:未定义的标志符 “cout”
解决:在c_cpp_properties.json配置文件的"includePath"添加上mingw的一些解析路径
问题:“找不到任务g++.exe build active file”
解决方案:需要在 .vscode 文件中配置 tasks.json 中的 label 字段与 launch.json 中的 preLaunchTask 字段一致.