std::cout in debug is displayed in terminal only when the program terminates
So lets say I have a program like this :
#include <iostream>
#include <typeinfo>
using namespace std;
class A {
public:
A() { cout << "1"; }
A(const A &obj) { cout << "2"; }
};
class B : public A {
public:
B() { cout << "3"; }
B(const B &obj) { cout << "4"; }
};
class C : virtual public A {
public:
C() { cout << "5"; }
C(const C &obj) { cout << "6"; }
};
class D : B,C {
public:
D() { cout << "7"; }
D(const D &obj) { cout << "8"; }
};
int main() {
D d2;
D d(d2);
return 0;
}
and I want to follow on the building process of each object (inheritance process practice) with cout, the problem is that the final phrase is displayed in 1 piece when the program terminates after return 0, instead of printing a number 1 by 1 in each step I take with "step into". is there any way to configure it instead of using fflush (stdout) in each cout command?
Thank you.
请先登录再写评论。
Hi! What OS, toolchain and CLion version do you use?
I doubt CLion can be configured to always flush the output stream. I think that behavior is platform-specific. Could be wrong about that though.
However, just sending std::flush to the stream should do what you want. I realize this approach isn't what you wanted for some reason though.