Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

244
Views
Eclipse C++ console print order linux

I know there many subjects about this but none of them helps me.

I use in my C/C++ project std::cout and std::cerr to print info (cout) or error (cerr). But when executing it they don't print in the right order, they seems to "group print". Sometime all cerr then all cout and sometime all cout first then all cerr.

I tried to flush() after every line, don't work. (luckily, it would be awful having to use it every time ...). Also tried setvbuf(stdout, NULL, _IONBF, 0); same issue...

If run program directly in linux's console, order is good but eclipse console more useful due to colors.

Here code sample

#include <iostream>

int main(int argc, char** argv)
{
    std::cerr << __LINE__ << std::endl;
    std::cerr << __LINE__ << std::endl;
    std::cout << __LINE__ << std::endl;
    std::cerr << __LINE__ << std::endl;
    std::cerr << __LINE__ << std::endl;
    std::cout << __LINE__ << std::endl;
}

And console print

11
12
14
15
13
16

==> Wrong order ... In this example cerr comes out before cout

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Ok the situation is as follows, std::cout is added into a buffor, and std::cerr does not. std::cerr is faster and it does not need to be flushed. Also std::cerr and std::cout uses different streams.

The problem here is that std::cerr shows right away and std:cout needs to be flushed before it's showed.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!