title: C++ Reading Txt File, Line by line, storing multiple types in two lists, if present
body: <p>I've been learning about reading text files recently, and have successfully been able to read, and store data into lists - which then allows me to sort nicely (I'm trying to learn to use lists, rather than Vectors atm, so answer using that would be perfect). </p>
  
  <p>My problem is, when there is a change in the <code>textfiles</code> data types, where the structure is slightly different - I'll provide an example:</p>
  
  <h2>Test.txt</h2>
  
  <pre><code>Joe Smith 15 
  
  Eileen Jones 4
  
  Joey 12
  
  James Rush 2
  </code></pre>
  
  <p>So, basically, I'm trying to read a file, which has changing data types, of an unspecified length. I'd ideally like to keep the first and last name together in a single stringstring, and then separate the integer - however also provide scope for a single string to be present. </p>
  
  <p>From my searches, I've found that I should take the entire line as a string, then use <code>stringstream</code> to split the information - only problem, is that if the data changes from having two strings, to only one before the integer, then it won't store.</p>
  
  <p>From there I have to store strings in one list and ints in another, whilst keeping first/last name together if they are both there - or not, if it's just a single string.</p>
  
  <p>Hopefully this makes sense. I've been searching for days, and just can't find a way to do it. I would really appreciate some help!</p>
  
  <p>Also, my code so far:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;list&gt;
  #include &lt;fstream&gt;
  
  
  using namespace std;
  
  int main()
  {
      list &lt;string&gt; eachLine;
  
      list &lt;string&gt; personName;
  
      list &lt;int&gt; favouriteNumber;
  
      int intStore;
      string strStore;
  
      ifstream userFile("Test.txt");
  
      // check if file is open
      if (!userFile)
      {
          cout &lt;&lt; "\n\nCannot open file!\n\n";
          cin.get();
          return 1;
      }
  
  
      while (!userFile.eof())
      {
          userFile &gt;&gt; stringStore;
  
          eachLine.push_back(tempStore);
  
      }
  
      // ?????? Split Strings from list (eachLine) - so to have either
      // &lt;string&gt;, &lt;string&gt;, &lt;int&gt; or &lt;string&gt;, &lt;int&gt;. Then store
      // strings in list1 (personName) and ints in 
      // list2 (favouriteNumber)
  
  
      system("pause");
  
      return 0;
  }
  </code></pre>