【问题标题】:Why Debugging is not easy or built in VSCode for C++ as that for JavaScript?为什么调试不像 JavaScript 那样容易或内置于 C++ 的 VSCode 中?
【发布时间】:2020-11-30 18:17:39
【问题描述】:

每次,我点击运行和调试,cpp文件,我得到这个文件,“launch.json” .youtube上这方面的帮助不多,而且我也无法从VSCode官方文档中解决这个问题。

我的 cpp 文件

#include<iostream>
using namespace std;
int main(){
    int iam;
    std::cout<<"salam from Pakistan!";
    cout<<endl<<"enter number";
    cin>>iam;
    return 0;
}

launch.json 文件

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

另外,我不知道这个 tasks.json 文件是什么,我在 .vscode 文件夹中看到了该文件以及 launch.json。

【问题讨论】:

  • 你的launch.json 看起来像一个tasks.json 文件,VS 代码可以通过从调试菜单中选择一个选项为你生成一个基本的launch.json
  • VSC 不是 IDE,它是一个有好处的编辑器。因为它在 JavaScript 上运行,可能它最支持它,如果你想要一个简单的 C++ 开发环境,请使用 Visual Studio,Qt Creator

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


【解决方案1】:

删除您当前的launch.json,然后打开您的文件并转到Run -> StartDebugging。这应该会指导您选择编译器和调试器,并且应该会生成您的 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++ - Build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: g++ build active file",
            "miDebuggerPath": "/usr/bin/gdb"
        }
    ]
}

如您所见,您定义了 task 而不是 configuration

tasks.json 看起来像这样:

{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: g++ build active file",
            "command": "/usr/bin/g++",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "/usr/bin"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Generated task by Debugger"
        }
    ],
    "version": "2.0.0"
}

【讨论】:

    猜你喜欢
    • 2021-06-18
    • 2011-05-13
    • 2013-02-12
    • 2011-05-02
    • 1970-01-01
    • 2020-12-02
    • 1970-01-01
    • 1970-01-01
    • 2020-08-02
    相关资源
    最近更新 更多