0

Hi I'm writing some debug output with std::cout with this code:

EDIT: as suggested I added a std::flush on each cout and an std::endl on each iteration

int
    index = 0,
    size = vector.size();
for (iterate trough a vector)
{
    std::cout << "Actual element: " << index+1 << "/" << size << std::flush;
    ...
    if (bad element)
    {
        std::cout << " -> Bad Element" << std::flush;
    }
    std::cout << std::endl;
}

The bad element string appear only after the successive element, why? What am I missing?

Thanks a lot!

Michele mpp Marostica
  • 2,445
  • 4
  • 29
  • 45

1 Answers1

1

You should have a std::cout << std::flush (or std::cout << std::endl) in your for loop which is always done (even without bad elements), or at least after your for loop....

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547