Input reading: two values (separated by whitespace) per line 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 &lt;iostream&gt;
#include &lt;sstream&gt;
#include &lt;deque&gt;

// Splits a string by its whitespaces and returns a deque with each item.
deque&lt;string&gt; split(string original) {
    deque&lt;string&gt; result;
    string buffer;
    stringstream stream(original);
    while (stream &gt;&gt; buffer) {
        result.push_back(buffer);
    }
    return result;
}

// Reads two integer parameters from a single line, separated by a whitespace
void getTwiceInput(int &amp;a,int &amp;b) {
    string input;
    getline(cin,input);
    deque&lt;string&gt; deck = split(input);
    stringstream ss;
    ss &lt;&lt; deck[0];
    ss &gt;&gt; a;
    ss.clear();
    ss &lt;&lt; deck[1];
    ss &gt;&gt; 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.
I can think of two more ways of doing it.

1. Using iostream iterators. (Following code is from here)

#include &lt;iostream&gt;
#include &lt;iterator&gt;
using namespace std;

int main () {
  double value1, value2;
  cout &lt;&lt; "Please, insert two values: ";

  istream_iterator&lt;double&gt; eos;         // end-of-stream iterator
  istream_iterator&lt;double&gt; iit (cin);   // stdin iterator

  if (iit!=eos) value1=*iit;

  iit++;
  if (iit!=eos) value2=*iit;

  cout &lt;&lt; value1 &lt;&lt; "*" &lt;&lt; value2 &lt;&lt; "=" &lt;&lt; (value1*value2) &lt;&lt; endl;

  return 0;
}


2. Converting string to int using atoi() rest everything will be same.