title: obtaining values from a vector
body: <p>my code gets an error after inputting a string. i needed to have a string input (eg. add fruit) which will be put inside my vector by the "add" keyword. But when i also input a single word (eg. print) ,to print the elements in my vector. it wont work. any insights?</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;sstream&gt;
  #include &lt;string&gt;
  #include &lt;vector&gt;
  #include &lt;algorithm&gt;
  using namespace std;
  
  
  vector &lt;string&gt; separate(string str){
     string word = "";
     vector &lt;string&gt; v = {0,0};
     for (auto x : str)
     {
         if (x == ' ')
         {
             v[1] = word;
             word = "";
         }
         else
         {
             word = word + x;
         }
     }
      v[0] = word;
      return v;
  
  }
  
  int main(){
  
  
      string user_input, command, item;
      int cmds;
      vector &lt;string&gt; result;
  
  
  
      while (1){
          cout &lt;&lt; "Enter a command: ";
          getline(cin, user_input);
  
          vector &lt;string&gt; arrcmd = separate(user_input);
          (arrcmd.size() == 1) ? (command = arrcmd[0]) : (command = arrcmd[1], item = arrcmd[0]);
          cout &lt;&lt; arrcmd.size() &lt;&lt; endl;
  
   /*       command = arrcmd[0], item = arrcmd[1];   */
          cout &lt;&lt; command &lt;&lt; " " &lt;&lt; item &lt;&lt; endl;
  </code></pre>