5

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:

  • Output: empty
  • Problems: empty
  • Terminal 1: cppdbg: temp empty
  • Terminal 2: Task - g++ build active file content
  • Debug console: content

How to fix this?


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

8
  • Probably by adding a newline to the string. The output may be buffered. Commented May 14, 2019 at 5:50
  • 1
    cout << "Hello World\n"; or even better cout << "Hello World" << endl;. endl outputs a newline and flushes the stream. Commented May 14, 2019 at 5:58
  • Thanks, putting an endl worked (\n didn't), but that is very weird behavior from VSCode. Commented May 14, 2019 at 6:06
  • 2
    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 Commented May 14, 2019 at 6:19
  • @john there seems to be recent contra information to using std::endl, see ACCU Overload 149 - Don't Use std::endl. I don't think it is a showstopper either way, but curios about your comment. Commented May 14, 2019 at 7:01

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.