Search
 
SCRIPT & CODE EXAMPLE
 

CPP

how to take space separated input in c++

string z,s;
 while (true)
    {
      cin>>z;
      s+=z;
      if(cin.peek()=='
')
      break;
    }
................................
	        OR/
.................................
string s;
getline(cin,s);
Comment

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() == '
') {
        break;
    }
    
}

cout << "result: " << sum << endl;
return 0;
}
Comment

how to take space separated input in c++

#include <string>
#include <vector>
...
  string rawInput;
  vector<String> numbers;
  while( getline( cin, rawInput, ' ' ) )
  {
    numbers.push_back(rawInput);
  }
Comment

PREVIOUS NEXT
Code Example
Cpp :: c function as paramter 
Cpp :: c++ output current timestamp 
Cpp :: after login redirect to dashboard in nuxt 
Cpp :: how to print in new lines in C++ 
Cpp :: std::copy C ++ 
Cpp :: insert in vector 
Cpp :: c++ multiple inheritance 
Cpp :: cpp detect os 
Cpp :: c++ access second last element of vector 
Cpp :: create matrix cpp 
Cpp :: factorial of large number 
Cpp :: cpp template 
Cpp :: c++ program to find lcm of two numbers 
Cpp :: how to add space in c++ 
Cpp :: c++ math 
Cpp :: abstraction in cpp 
Cpp :: how to input in cpp 
Cpp :: c++ fonksion pointer 
Cpp :: C++ wchar_t 
Cpp :: resharper fold if statement 
Cpp :: pop off end of string c++ 
Cpp :: vector::at() || Finding element with given position using vector in C++ 
Cpp :: c++ cin 
Cpp :: modular exponentiation algorithm c++ 
Cpp :: c++ convert to assembly language 
Cpp :: c++ map 
Cpp :: Temparory Email Id 
Cpp :: minimum or maximum in array c++ 
Cpp :: kadane algorithm with negative numbers included as sum 
Cpp :: c++ custom printf 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =