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 :: how to iterate throguh a string in c++ 
Cpp :: How to pause a c++ program. 
Cpp :: C++ press enter to continue function 
Cpp :: convert string to lpstr 
Cpp :: bitwise count total set bits 
Cpp :: Parenthesis Checker using stack in c++ 
Cpp :: clear the input buffer in cpp 
Cpp :: print 2d array c++ 
Cpp :: get value of enum cpp 
Cpp :: array max and minimum element c++ 
Cpp :: input in c++ 
Cpp :: size of stack in c++ 
Cpp :: string substr c++ 
Cpp :: how to delete a file in cpp 
Cpp :: find index of element in array c++ 
Cpp :: c++ hello world 
Cpp :: C++ Area and Perimeter of a Rectangle 
Cpp :: cannot jump from switch statement to this case label c++ 
Cpp :: push local branch to another remote branch 
Cpp :: c++ if else 
Cpp :: currency converter c++ 
Cpp :: c++ filesystem read directory 
Cpp :: 2d vector in cpp 
Cpp :: compute power of number 
Cpp :: operand-- c++ 
Cpp :: matrix dynamic memory c++ 
Cpp :: accumulate() in c++ 
Cpp :: best time to buy and sell stock leetcode solution 
Cpp :: how to format decimal palces in c++ 
Cpp :: search by value in map in stl/cpp 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =