I had searched for "buffer" in c++ quite a lot before I ask it here, all answers I got were "buffer in C++ will not be flushed automatically unless a specific statement like std::flush
or std::endl
is specified. However, I found that the buffer is always automatically flushed in my code.
#include <iostream>
using namespace std;
int main(){
int i;
cout << "begin...\n";
for (i = 0; i<1000000000; i++);
cout << "end" << endl;
cin.get();
return 0;
}
What I got is "begin..." and a new line (\n) were shown first. Then after a few seconds, "end" is shown. Does that mean the buffer was flushed after
cout << "begin...\n";
Or is my understanding wrong?