Gaurang Tandon
Gaurang Tandon

Reputation: 6753

VS Code C++ program does not display any output while debugging

Take a simple C++ file like this:

#include <iostream>
using namespace std;

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

    cout << "Hello World";
    return 0;
}

Set breakpoint at return 0. Setup this launch config:

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

Goto debug tab in left sidebar and click green run button.

Expected situation: I can see Hello World somewhere.
Actual situation: I cannot see Hello World anywhere.

Right side tabs:

How to fix this?


Setup: VS Code 1.33.1 (Official Snap build) on Ubuntu 18.04

Upvotes: 5

Views: 6245

Answers (1)

Gaurang Tandon
Gaurang Tandon

Reputation: 6753

According to helpful comments above, also I'll quote 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

Thus I needed to add an extra std::endl to my std::cout statement.

Upvotes: 4

Related Questions