Strange cout << Boost :: posix_time behavior

I want to calculate the cycle time it takes to complete.

I am doing something like:

ptime before = second_clock::local_time(); //get current time
cout << "Started: "<< before << " ... processing ...";
while(foo) {
....
}
ptime after = second_clock::local_time(); // get Current time
cout << "Processing took" << after - before;

This will output: Started: "for a while"

then I wait for the loop to complete before I see "... processing ..."

Why? First, it should delete all the text, and then go into a loop.

If I changed the first cout to:

cout <"Start:" <<before;

It does not even show the time until the end of the cycle.

What is the strangest thing I've ever seen ... it seems like something is wrong with my understanding of time acceleration.

I use boost :: threads in my code, but the workers are scattered inside the loop, so I don’t see how this could be related to this problem.

Can anyone help me here?

+3
1

ostream cout , , , , .

cout ,

std::cout << std::flush;

std::endl, "\n", std::flush.

+2

Source: https://habr.com/ru/post/1792524/


All Articles