gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 14:50:18 24 4
gpt4 key购买 nike

以这样一个简单的 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;
}

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

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

预期情况:我可以看到 Hello World某处。
实际情况:我可以 不是 Hello World任何地方。

右侧标签:
  • 输出 : 空
  • 问题 : 空
  • 1 号航站楼 :cppdbg: temp
  • 2 号航站楼 :Task - g++ build active file content
  • 调试控制台 :content

  • 如何解决这个问题?

    设置 : Ubuntu 18.04 上的 VS Code 1.33.1(官方 Snap 构建)

    最佳答案

    根据上面有用的评论,我也会引用 Alan :

    It's not vs codes behaviour, your operating system buffers output before printing to the console, this is entirely normal and fairly universal across all platforms



    因此我需要添加一个额外的 std::endl到我的 std::cout陈述。

    关于c++ - VS Code C++ 程序在调试时不显示任何输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56123598/

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