【问题标题】:VSCode <error reading variable> when viewing array elements during debuggingVSCode <error reading variable> 在调试期间查看数组元素时
【发布时间】:2021-02-08 09:20:01
【问题描述】:

我在VSCode中调试如下代码:

int main() {
    char arr1[] = {'t', 'e', 's', 't', '\0'};
    char arr2[] = "test";
    int arr3[] = {1, 2, 3};
    double arr4[] = {1.1, 2.2, 3.3};
}

前两个数组的元素显示为:

116 '<error reading variable>
101 '<error reading variable>
115 '<error reading variable>
116 '<error reading variable>
0 '<error reading variable>

而最后两个数组的元素显示数字的实际值。

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,
            "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"
        }
    ]
}

我该怎么做才能让前两个数组显示数组中的字符?

【问题讨论】:

    标签: c++ debugging visual-studio-code vscode-debugger


    【解决方案1】:

    以下solution 解决了该问题:

    我在这个中文博客中找到了解决方法 https://blog.csdn.net/m0_46304383/article/details/113487503 (用谷歌翻译翻译)。似乎是 Windows 10 UTF-8 问题。我希望它也可以帮助你@georgian3。

    解决方法是:“Windows 设置”->“时间和语言”-> “区域”->“其他日期->时间和区域设置”->“更改日期” -> 时间或数字格式” -> “管理” -> “更改系统区域设置” -> 取消勾选“Beta版本:使用Unicode UTF-8提供 全球语言支持” -> 重启电脑

    【讨论】:

    • 谢谢@George Tian,遇到了同样的问题,找到修复取消选中“Beta 版:使用 Unicode UTF-8 提供全球语言支持”的唯一方法
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-17
    相关资源
    最近更新 更多