Answers for "how to take space separated input in c++"

C++
1

how to take space separated input in c++

string z,s;
 while (true)
    {
      cin>>z;
      s+=z;
      if(cin.peek()=='\n')
      break;
    }
................................
	        OR\/
.................................
string s;
getline(cin,s);
Posted by: Guest on July-10-2021
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
0

how to convert n space separated integers in c++

int i, n, arr[100];

scanf("%d", &n);
for (i = 0; i < n; ++i)
    scanf("%d", &arr[i]);
Posted by: Guest on June-28-2020

Code answers related to "how to take space separated input in c++"

Browse Popular Code Answers by Language