title: Converting a string of numbers into an int vector c++
body: <p>Is there a simple way to convert a string of numbers separated by spaces into a vector of ints or something that I can easily convert into a vector? </p>
  
  <p>I am creating an input operator (>>) to make a binary tree using values input from command line. And this is the main that goes with it</p>
  
  <pre><code>int main(int argc, char **argv)
  {
  stringstream stream;
  stream &lt;&lt; " 10" &lt;&lt; " 11" &lt;&lt; " 10" &lt;&lt; " 2" &lt;&lt; endl;
  tree = new binary_tree();
  stream &gt;&gt; *tree;
  if (tree-&gt;inorder() != string("7 10 11")) //inorder() prints the tree in order
  cout &lt;&lt; "Test passed" &lt;&lt; endl;
  delete tree;
  
  return 0;
  }
  </code></pre>
  
  <p>The problem I am having is that while I can create and print the values that I need, I can't convert them and put them into a vector - for which I have a working defined method that creates a tree from the values.</p>
  
  <pre><code>std::istream&amp; operator&gt;&gt;(std::istream &amp;in, binary_tree &amp;value)
  {
  vector&lt;int&gt; input_tree;
  string readline;     
  getline(in, readline);
  cout &lt;&lt; "(" &lt;&lt; readline &lt;&lt; ")" &lt;&lt; endl; //prints correctly - (10 11 10 2)
  
      //where I need to insert insert values into vector
  
  for(int i = 0; i &lt; input_tree.size(); i++)
  {
      insert(input_tree[i], value);    //inserts the values from a vector into a binary tree
  }
  
  return in;  
  } 
  </code></pre>
  
  <p>I have tried looping through the string and using stoi() on each character but it always errored whenever the spaces were causing errors.</p>
  
  <p>Thanks for any help and sorry if I've missed any important information out.</p>