dimanche 1 octobre 2017

C++ cin is used in while loop but console screen is not held

I am using cin as condition for while loop where it accepts an integer unless an end of file or a character is entered. But the console window disappears just after the result. How can I hold the screen

#include<iostream>

using namespace std;

int main() {


    int num = 0, sum = 0;

    while (cin >> num) {
        sum += num;
    }


    cout << "Sum is: "
        << sum
        << endl;

    cout << endl;

    cin.get();
    return 0;
}

Aucun commentaire:

Enregistrer un commentaire