title: How to get a word vector from a string?
body: <p>I want to store words separated by spaces into single string elements in a vector.
  The input is a string that may end or may not end in a symbol( comma, period, etc.)
  All symbols will be separated by spaces too.</p>
  
  <p>I created this function but it doesn't return me a vector of words. </p>
  
  <pre><code>vector&lt;string&gt; single_words(string sentence)
  {
      vector&lt;string&gt; word_vector;
      string result_word;
  
      for (size_t character = 0; character &lt; sentence.size(); ++character)
      {
          if (sentence[character] == ' ' &amp;&amp; result_word.size() != 0)
          {
              word_vector.push_back(result_word);
              result_word = "";
          }
          else
              result_word += character;
      }
      return word_vector;
  }
  </code></pre>
  
  <p>What did I do wrong?</p>