When debugging an app using std::cout to print something, nothing appears in the debug console (3rd tab, not external console). One of the exceptions seems to be the use of std::endl:
#include <iostream>
#include <Windows.h>
using namespace std;
int main() {
while(true) {
Sleep(500);
std::cout << "Hello world!" << std::endl; // Works
}
}
#include <iostream>
#include <Windows.h>
using namespace std;
int main() {
while(true) {
Sleep(500);
std::cout << "Hello world!\n"; // Doesn't work
// std::cout << "Hello world!"; // Doesn't work
// std::cout << "Hello world!" << std::flush; // Doesn't work
}
}
In the first example our lines appear over time, while on the second doesn't appear at all (or the console refreshes somewhere around 60 secs). I think this is a bug but I'm not sure, so what is a workaround? Maybe I have to configure something instead? I found this problem while working on something else: C++: cannot see output in VS Code while debugging
Edit
The problem is what to do when u wanna output something without a new line
std::endlis\nplusstd::flush, which isn't one of the options you seem to have tried.\r\nshould flush automatically, however this is an implicit contract with the OS. Just callstd::flush.DEBUG CONSOLEis the right one, I'm sure of that, asTERMINALshows building stuff. I'm using alaunch.jsonto debug my code.std::flushdoes not have any effect without\n. I need to be able to get stuff on the console without forcing a line end, and without using an external console (because the later one doesn't make sense)