Sometimes, I need to read two integer parameters in a single input line, separated by a whitespace.I have these two functions that seem to do the job just fine:#include <iostream>#include <sstream>#include <deque>// Splits a string by its whitespaces and returns a deque with each item.deque<string> split(string original) {    deque<string> result;    string buffer;    stringstream stream(original);    while (stream >> buffer) {        result.push_back(buffer);    }    return result;}// Reads two integer parameters from a single line, separated by a whitespacevoid getTwiceInput(int &a,int &b) {    string input;    getline(cin,input);    deque<string> deck = split(input);    stringstream ss;    ss << deck[0];    ss >> a;    ss.clear();    ss << deck[1];    ss >> b;}So in my program I do this call:int x,y;getTwiceInput(x, y);Is there an easier way to achieve this? It is a bit tiring having to type all of that just to achieve this for every programming challenge given.
Input reading: two values (separated by whitespace) per line
c++
I would recommend to use std::stringstream for split. Here is how I think this function would look like:#include <sstream>#include <vector>#include <iterator>template<typename T>std::vector<T> split(const std::string& line) {    std::istringstream is(line);    return std::vector<T>(std::istream_iterator<T>(is), std::istream_iterator<T>());}And here is how to use it:std::string line = 1.2 3.4 5.6e7;std::vector<double> vec = split<double>(line);This method is more general and can split more than two elements as well as parse them to any type provided as template parameter, as long as it is readable by operator>>.