lundi 25 juillet 2016

terminate while loop using character

I need help with the following snippet:

Using string in the following loop terminates:

int main() {
string in;
while(1){
    cin >> in;
    if (in == "|")
        break;
}

But using int in the following loop does not terminates:

int main() {
int in;
while(1){
    cin >> in;
    if (in == '|')
        break;
    else 
        cout<< in << "\n";
}

I want to terminate the last shown snippet. Is it possible to do using int in. I've seen the post C++ Terminate loop using a char input to int but no solution.

Aucun commentaire:

Enregistrer un commentaire