Answers for "how do i take the input of a line of integers separated by a space in c++"

C++
0

input n space separated integers in c++

int main() {
int sum = 0;
cout << "enter number" << endl;
int i = 0;
while (true) {
    cin >> i;
    sum += i;
    //cout << i << endl;
    if (cin.peek() == 'n') {
        break;
    }
    
}

cout << "result: " << sum << endl;
return 0;
}
Posted by: Guest on June-11-2021

Code answers related to "how do i take the input of a line of integers separated by a space in c++"

Browse Popular Code Answers by Language