title: C++ split string
body: <p>I am trying to split a string using spaces as a delimiter. I would like to store each token in an array or vector.</p>
  
  <p>I have tried.</p>
  
  <pre><code>    string tempInput;
      cin &gt;&gt; tempInput;
      string input[5];
  
      stringstream ss(tempInput); // Insert the string into a stream
      int i=0;
      while (ss &gt;&gt; tempInput){
          input[i] = tempInput;
          i++;
      }
  </code></pre>
  
  <p>The problem is that if i input "this is a test", the array only seems to store input[0] = "this". It does not contain values for input[2] through input[4].</p>
  
  <p>I have also tried using a vector but with the same result.</p>