title: vector name storage list program suddenly not displaying list
body: <p>Novice C++ user trying to practice program building. The point of this program is just simple name storage with vectors. </p>
  
  <p>My previous program <a href="https://pastebin.com/MG1hHzgK" rel="nofollow noreferrer">https://pastebin.com/MG1hHzgK</a> works perfectly fine for just adding first names.</p>
  
  <p>This upgraded version is supposed to have an input of <code>First Last</code> names then it is converted into <code>Last, First</code> name before being added to the list.</p>
  
  <p>My problem is that after I input names, they arent added to the list. The differences between my previous program and current one are all in the function <code>addNames</code> and to me it looks correct when its obviously not.</p>
  
  <p>Any hints or help is greatly appreciated.</p>
  
  <pre><code>#include &lt;conio.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  // Prototypes
  string addNames(vector &lt;string&gt;&amp; nameList);
  string removeName(vector &lt;string&gt;&amp; nameList); 
  int findName (vector &lt;string&gt;&amp; nameList);
  void showList(vector &lt;string&gt;&amp; nameList);
  void commandList(vector &lt;string&gt;&amp; nameList);
  void inputCall(vector &lt;string&gt;&amp; nameList);
  void sortList(vector &lt;string&gt;&amp; nameList);
  
  
  int main() 
  {
  vector &lt;string&gt; nameList;
  commandList(nameList);
  }
  
  void commandList(vector &lt;string&gt;&amp; nameList) 
  {   
      cout &lt;&lt; "\nPress any key to continue..." &lt;&lt; endl;
      getch();
      system("cls");
  
      cout &lt;&lt; "Enter a Command " &lt;&lt; endl;
      cout &lt;&lt; "&lt;A&gt; - Add names to the list" &lt;&lt; endl;
      cout &lt;&lt; "&lt;R&gt; - Remove a name from the list" &lt;&lt; endl;
      cout &lt;&lt; "&lt;F&gt; - Search for a name on the list" &lt;&lt; endl;
      cout &lt;&lt; "&lt;L&gt; - Show current state of the list" &lt;&lt; endl;
      cout &lt;&lt; "&lt;S&gt; - Sort the list" &lt;&lt; endl;
      cout &lt;&lt; "&lt;Q&gt; - Ends the program" &lt;&lt; endl; 
          inputCall(nameList);
  }
  
  // ---------------------------------------------------------------------------------------------------------------------------------------------------------------------  
  string addNames(vector &lt;string&gt;&amp; nameList)
  {
      string input;
      int pos = input.find(' ');
  
          nameList.clear();
          for (;true;)
          {
              cout &lt;&lt; endl;
              cout &lt;&lt; "Enter a Name or 'Stop' to end name entry: " &lt;&lt; endl;
              getline(cin, input);
  
              if (input == "Stop" || input == "stop"){
                  commandList(nameList);
  
  
          }   else if(pos != -1) {
                  string first = input.substr(0, pos);
                  string last = input.substr(pos + 1);
                  input = last + "," + first;     
                      nameList.push_back(input);
                      commandList(nameList);
          }        
  }
  }
  
  // ---------------------------------------------------------------------------------------------------------------------------------------------------------------------   
  string removeName(vector &lt;string&gt;&amp; nameList)
  {    
      string x;
  
      cout &lt;&lt; endl;
      cout &lt;&lt; "Enter the name to remove: " &lt;&lt; endl;
      cin &gt;&gt; x;  
  
      for (int i=0; i &lt; nameList.size(); ++i)  {      
          if (nameList[i]== x) nameList[i]="";
          }
              commandList(nameList); 
  }
  
  // ---------------------------------------------------------------------------------------------------------------------------------------------------------------------  
  int findName (vector &lt;string&gt;&amp; nameList)
  {
      string target;
      int i, x=0;
      int p=0;
  
      cout &lt;&lt; endl;
      cout &lt;&lt; "Enter a name to search for: " &lt;&lt; endl; 
      cin &gt;&gt; target;
  
      if (target == "Quit" || target == "quit") {exit(0); 
      }
          for (int i=0; i &lt; nameList.size(); i++)
          {
          if (nameList[i] == target) 
          {   
          cout &lt;&lt; endl;
          cout &lt;&lt; "The entered name is listed as #" &lt;&lt; p+1 &lt;&lt; '.' &lt;&lt; endl;
          commandList(nameList);
          return p;
      }
      if (nameList[i] == "") {
          p--;
      }
          p++;
      }
      cout &lt;&lt; endl;
      cout &lt;&lt; "Name not found!" &lt;&lt; endl;
      commandList(nameList);
      return -1;
  } 
  
  // ---------------------------------------------------------------------------------------------------------------------------------------------------------------------     
  void showList(vector &lt;string&gt;&amp; nameList)
  {
      cout &lt;&lt; endl;
      cout &lt;&lt; "The current state of the list is: " &lt;&lt;endl;
  
      for (int i=0; i&lt;nameList.size(); i++)
      if(nameList[i] !="")
          cout &lt;&lt; nameList[i] &lt;&lt; endl;
  
      commandList(nameList);
  }  
  
  void sortList(vector &lt;string&gt;&amp; nameList) 
  {
  string temp;
      for (int i=0; i &lt; nameList.size()-1; i++)
      {      
          for (int j=0; j &lt; (nameList.size()-i-1); j++)
          {
  
          if (nameList[j] &gt; nameList[j+1])
              {
                   temp = nameList[j];
                   nameList[j] = nameList[j+1];
                   nameList[j+1] = temp;
              }
          }
      }
      cout &lt;&lt; endl;
      cout &lt;&lt; "The list has been sorted alphabetically." &lt;&lt; endl;
  
  commandList(nameList);
  } 
  
  // ---------------------------------------------------------------------------------------------------------------------------------------------------------------------    
  void inputCall(vector &lt;string&gt;&amp; nameList) // Function to complement the menu for switch casing
  {
      bool running = true;
  
      char input;
          do {
              input = getch();
              switch(input)
              {
              case 'a': addNames(nameList);break;
              case 'A': addNames(nameList);break;
              case 's': sortList(nameList);break;
              case 'S': sortList(nameList);break;
              case 'l': showList(nameList);break;
              case 'L': showList(nameList);break;
              case 'f': findName(nameList);break;
              case 'F': findName(nameList);break;
              case 'r': removeName(nameList);break;
              case 'R': removeName(nameList);break;
              case 'q': exit(0);break;
              case 'Q': exit(0);break;
              default : cout &lt;&lt; "Unknown Command: Enter a command from the menu." &lt;&lt; endl; continue;
              }
      } while (running);
  }
  </code></pre>