VS Code C++ 程序在调试时不显示任何输出

Gau*_*don 5 c++ visual-studio-code vscode-debugger

采用一个简单的 C++ 文件,如下所示:

#include <iostream>
using namespace std;

int main(void)
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cout << "Hello World";
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

设置断点在return 0. 设置此启动配置:

{
    "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": "g++ build active file",
    "miDebuggerPath": "/usr/bin/gdb"
 }
Run Code Online (Sandbox Code Playgroud)

转到左侧边栏中的调试选项卡,然后单击绿色运行按钮。

预期情况:我能看到Hello World某处。
实际情况:我什么地方都看不到Hello World

右侧选项卡:

  • 输出:空
  • 问题:空
  • 1 号航站楼cppdbg: temp
  • 2号航站楼Task - g++ build active file 内容
  • 调试控制台内容

如何解决这个问题?


设置:Ubuntu 18.04 上的 VS Code 1.33.1(官方 Snap 版本)

Gau*_*don 4

根据上面有用的评论,我还要引用艾伦的话:

这不是 vs 代码行为,您的操作系统在打印到控制台之前缓冲输出,这是完全正常的,并且在所有平台上相当普遍

std::endl因此我需要在我的陈述中添加额外内容std::cout