我写了一个简单的 C++(11)
程序来测试Windows中Visual studio代码中的调试器。我正在使用MinGW发行版的编译器选项。我已经设置了我的 tasks.json
和 launch.json
根据这里的文档。https:/code.visualstudio.comdocscppconfig-mingw。
这里是示例cpp代码。
typedef std::vector<int> vi;
int main(int argc, char const *argv[])
{
fast();
int tests = 1;
cin >> tests;
while(tests--)
{
int n = 5, k = 25;
cin >> n >> k;
vi permutation(n);
for (int i = 0; i < n; i++)
{
cin >> permutation[i];
}
// vi permutation = {5,4,3,2,1};
auto ans = solve(permutation, k);
// other logic goes here
}
return 0;
}
我的 tasks.json
文件。
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "C/C++: g++.exe build active file",
"command": "C:\\MinGW\\bin\\g++.exe",
"args": [
"-g",
"-std=c++11",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "C:\\MinGW\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"echo": false,
"reveal": "always",
"focus": true,
"panel": "shared",
"clear": false,
"showReuseMessage": false
},
}
]
}
我的 launch.json
文件。
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++.exe - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe build active file"
}
]
}
根据文档,我应该看到一个类似这样的屏幕。 As per the doc, I should see a screen something like this:
我是不是设置错了什么?为什么我看不到容器的内容?我观察到,我也看不到其他容器的值。
当我从你提到的网站上安装MINGW时,我也面临同样的问题。然后,我从以下地方安装了MINGW SourceForge 中提到 维基 并开始正常工作。请大家试一试。