Search
 
SCRIPT & CODE EXAMPLE
 

CPP

How to take multiple int inputs in the same line in C++

cout << "Enter the values of a and b" << endl;
cin >> a >> b; //cascading the cin operator
Comment

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
    
}              */
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: Explicit conversion casting 
Cpp :: xor linked list 
Cpp :: second smallest element using single loop 
Cpp :: Snake Procession codechef solution in c++ 
Cpp :: Extended Euclid Algorithm Recursive Solution 
Cpp :: linked 
Cpp :: Calcular el número mayor y menor C++ 
Cpp :: ranged based for loop c++ 
Cpp :: The Three Topics codechef solution in c++ 
Cpp :: all usefull stls in cpp imports 
Cpp :: How to make an array dynamically using pointers 
Cpp :: github static std::string gen_name() { } // To do static int gen_number() { } // To do static int gen_grade() { } // To do double compute average() { } // To do 
Cpp :: python Difference Array | Range update query in O(1) 
Cpp :: c++ void to avoid functions 
Cpp :: c + + to c converter 
Cpp :: c++ to assembly 
Cpp :: c++ language 
Cpp :: this is my p phone number in punjabi 
Cpp :: run c++ files on chrome book 
Cpp :: lambda - print-out array and add comment 
Cpp :: how to get the last digit of a number 
Cpp :: what is the format specifier for dword c++ 
Cpp :: lcm recursive program in c++ 
Cpp :: passing a 2d array cpp 
Cpp :: 18 in 12 hour time 
Cpp :: how to include a library in arduino 
Cpp :: c++ return statement 
Cpp :: nazi crosshair c++ 
C :: pointer to a structure in c 
C :: wireless app debug android 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =