gpt4 book ai didi

arrays - gdb : in array while debugging VS code

转载 作者:行者123 更新时间:2023-12-05 03:47:33 25 4
gpt4 key购买 nike

我在调试过程中无法查看数组的内容。而不是我看到的字符。

我的代码:

#include <stdio.h>

int main()
{
char str[100] = {0};
fgets(str, 100, stdin);

return 0;
}

我在 VARIABLES 窗口中看到的内容:

enter image description here

但是当我尝试调试 int 数组时一切正常。

例子:

#include <stdio.h>

int main()
{
int str[100];
for (int i = 0; i < 100; i++)
{
str[i] = i+1;
}


return 0;
}

我看到的:

enter image description here

任务.json:

{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc.exe build active file",
"command": "C:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\bin\\gcc.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "C:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: \"C:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\bin\\gcc.exe\""
}
]
}

启动.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": "gcc.exe - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: gcc.exe build active file"
}
]
}

如何查看数组中的字符?

最佳答案

因为 pretty-printer 没有正确显示 utf-8 字符。要显示 utf-8 字符,请编辑 launch.json 中的 setupCommands:

  "setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Fix pretty-printing for gdb",
"text": "set charset UTF-8"
}
],

原始答案:VSCode debugger having issues with character encoding

关于arrays - gdb : <error reading variable> in array while debugging VS code,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64849170/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com