Michele mpp Marostica
Michele mpp Marostica

Reputation: 2472

c++ std::cout unespected output

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!

Upvotes: 0

Views: 225

Answers (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....

Upvotes: 1

Related Questions