Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

250
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda