Pergunta

When I write every C++ program, such as that one:

#include <iostream>
#include <string>

using namespace std;

int main()
{
    int n;
    cout << "Tell me where to start: ";
    cin >> n;
    while (n>0) {
        cout << n << "\n";
        n = n-1;
    }
    cout << "FIRE!";
    return 0;
}

I compile it with G++ and, when I run it, it works well, but when it finishes it displays the "logout" word after the program's last word, like this:

Tell me where to start: 10
10
9
8
7
6
5
4
3
2
1
FIRE!logout

[Process completed]

Why? And how can I remove it?

Foi útil?

Solução

It's not from your program. It's because the terminal is opened with the sole purpose of running your program, and as such when it exits, the terminal shuts down.

If you open a shell and manually run your executable, instead of this message, you'll simply get another command prompt.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top