Maf*_*fia 10 c++ gcc mingw visual-studio-code
我目前正在使用 VS Code 来学习 C++,因为它易于设置并且比 VS Studio 轻得多。但是,我无法做的一件事是在调试模式下查看数组(或字符串等)的元素。
我在这里搜索了解决方案,似乎启用漂亮的打印可以解决问题,但不幸的是它没有(我安装了 Python 3.6)。我也尝试过使用 VS Studio 编译器和调试器,但无法让它按照我想要的方式工作(基本上点击 F5 来编译单个 cpp 文件,而无需更改任何选项,只需单击一下)。
你们能帮我解决这个问题吗?我目前在 Windows 10 上使用 MinGW 编译器,具有以下任务文件:
"version": "2.0.0",
"tasks": [
{
"label": "echo",
"type": "shell",
"command": "g++",
"args": [
"-g", "${relativeFile}", "-o", "example"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
Run Code Online (Sandbox Code Playgroud)
并启动:
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/example.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
"preLaunchTask": "echo",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
Run Code Online (Sandbox Code Playgroud)
预先感谢!
对我来说这可行,但首先检查您是否有'c:\msys64\mingw64\share\gcc-8.3.0\python'
或'c:\usr\share\gcc-8.3.0\python'
文件夹并调整片段
launch.json
...
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "python import sys;sys.path.insert(0, 'c:\\msys64\\mingw64\\share\\gcc-8.3.0\\python');from libstdcxx.v6.printers import register_libstdcxx_printers;register_libstdcxx_printers(None)",
"ignoreFailures": false
},
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
...
Run Code Online (Sandbox Code Playgroud)
我使用的方法就像上面描述的Georgy 一样。
*((int(*)[10])array._M_impl._M_start)
Debug console output:
-exec p array
$7 = {<std::_Vector_base<int, std::allocator<int> >> = {_M_impl = {<std::allocator<int>> = {<__gnu_cxx::new_allocator<int>> = {<No data fields>}, <No data fields>}, _M_start = 0x2924cb0, _M_finish = 0x2924cd8, _M_end_of_storage = 0x2924cf0}}, <No data fields>}
-exec p *((int(*)[10])array._M_impl._M_start)
$8 = {41, 18467, 6334, 26500, 19169, 15724, 11478, 29358, 26962, 24464}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4885 次 |
最近记录: |