Why does Qt Creator add a new line after calling cout.flush ()?

The code is simple

#include <iostream> #include <unistd.h> using namespace std; int main() { for(int i = 0; i < 3; ++i) { cout << "1 "; cout.flush(); sleep(1); } } 

in the .pro file

 QT += core TARGET = ProjectName greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TEMPLATE = app 

If the output goes to Qt Creator "application exit" (the default location for the source code), each "1" starts on a new line.

If I compile and execute a separate * .cpp file in an Ubuntu terminal using g ++, it works properly.

If I create a new project in Qt Creator and the output goes to the Qt Creator console (a new window with a black background), it works properly.

Well, why does cout.flush () call a new line in the first case?

+7
c ++ flush cout qt-creator
source share
1 answer

Apparently, this is a Qt Creator error that they do not plan to resolve in the near future (at least it was in April 2015). I tested Qt Creator 3.5.1 (Qt 5.5.1) and the error still exists, although a new line is printed only after the first call to std::cout.flush() or adding the std::flush manipulator to the call to std::cout << .

In any case, the JIRA ticket for this error can be found here:

Debugging an application automatically launches a new line

+6
source share

All Articles