请问我的vscode配置出了什么问题导致这样的结果?

如图,c++ string调试时无法显示字符串内容。请问是不是配置哪里出了问题呢?

感谢!!

launch.json

{
  // 使用 IntelliSense 了解相关属性。 
  // 悬停以查看现有属性的描述。
  // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
    {
      "name": "(gdb) 启动",
      "type": "cppdbg",
      "request": "launch",
      "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
      "args": [],
      "stopAtEntry": true, //中断,设为true后在main函数处中断
      "cwd": "${fileDirname}", //"${workspaceFolder}",
      "environment": [],
      "externalConsole": false,
      "MIMode": "gdb",
      "miDebuggerPath": "D:\\mingw64\\bin\\gdb.exe",
      "setupCommands": [
        {
          "description": "为 gdb 启用整齐打印",
          "text": "-enable-pretty-printing",
          "ignoreFailures": true
        }
      ],
      "preLaunchTask": "g++.exe build active file"
    }
  ]
}

 

 

为啥我的有。。。神奇,我的 g++/gdb是8.1.0

sh: pause: command not found

CMakeLists.txt:

cmake_minimum_required(VERSION 3.0.0)

project(HELLO_WORLD VERSION 0.1.0)

 

include(CTest)

enable_testing()

 

add_library(HELLO_WORLD 你的文件.cpp)

 

set(CPACK_PROJECT_NAME ${PROJECT_NAME})

set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})

include(CPack)

 

 

不要 system("pause"); 完全没有问题。output:

I love you!
PS D:\VC\projects\hello_world> 

抱歉不是很理解

我的意思是调试时看不到string的内容

以前用visual studio调试就是可以直接看到的

这里调试显示的就是图中左边的样子

左边正常啊!没发现问题。

你的是 Linux 还是 macOS?

可能是 g++ 的版本不同。你用的是那版?

C:\msys64\mingw64\bin>g++ --version
g++ (Rev3, Built by MSYS2 project) 10.1.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

你可以更新g++:

https://repo.msys2.org/distrib/x86_64/msys2-x86_64-20210105.exe

就是说不能直接在调试面板显示字符串的内容“I love you”吗?

大哥,您直接用visual studio写c++ visual code 太轻量了

有些东西不全很正常

或者跟着这个走 https://code.visualstudio.com/docs/cpp/config-mingw

不过这太轻量了,该有的windows api 全都没有 我还是建议下 visual studio community  出去吃个饭的时间 1小时 就下完了 中间又不会中断

啊 ,你把s点开看看,string是个对象把,里面可能有保存的字符数组

 

对啊!我也有。

qq_42378668qq_42378668 就没有。能把你的 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": "(gdb) Launch",

            "type": "cppdbg",

            "request": "launch",

            //"program": "${fileDirname}/${fileBasenameNoExtension}.exe",

            "program": "${workspaceFolder}/build/${fileBasenameNoExtension}.exe",

            "args": [],

            "stopAtEntry": false,

            "cwd": "${workspaceFolder}",

            "environment": [],

            "externalConsole": true,

            "MIMode": "gdb",

            "miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",

            "preLaunchTask": "g++",

            "setupCommands": [

                {

                    "description": "Enable pretty-printing for gdb",

                    "text": "-enable-pretty-printing",

                    "ignoreFailures": false

                }

            ]

        }

    ]

}

 

我的launch.json

g++版本是9.2.0

建议题主尽快结题,把奖金给提供正解的用户。 谢谢