Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

Accepting multiple inputs on the SAME LINE C++

#include<iostream>
#include<sstream>      //***** THISSS must
#include<vector>

using namespace std;

int main()
{

// Below method is for when you DO NOT KNOW the number of input integers you are to accept
// Accepts these a String on one line and adds the INtegers onto a vector for storage and easier access

vector<int> pack;

string name;
getline(cin,name) ;
istringstream is(name);
int num;
while(is>>num){
    pack.push_back(num);
}

/*
for(int x:pack){
    cout << x << endl;  //      print optional...just for checking
    
}              */
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #Accepting #multiple #inputs #SAME #LINE
ADD COMMENT
Topic
Name
6+9 =