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: tempempty - Terminal 2:
Task - g++ build active filecontent - Debug console: content
How to fix this?
Setup: VS Code 1.33.1 (Official Snap build) on Ubuntu 18.04
cout << "Hello World\n";or even bettercout << "Hello World" << endl;.endloutputs a newline and flushes the stream.endlworked (\ndidn't), but that is very weird behavior from VSCode.std::endl, see ACCU Overload 149 - Don't Usestd::endl. I don't think it is a showstopper either way, but curios about your comment.