Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

252
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda