title: Splitting input string c++
body: <p>I am reading in a file, that contains data in this format on each line. <code>30304 Homer Simpson</code> I need to be able to pass this to the following constructor, the integer being the regNo, the name the rest of the string, and every student would have their own map of marks.</p>
  
  <pre><code>Student::Student (string const&amp; name, int regNo):Person(name)
  {
      regNo = regNo;
      map&lt;string, float&gt; marks;
  
  } 
  </code></pre>
  
  <p>I then have to add each student to a collection of students, which would be best, and how do I do this?</p>
  
  <p>So far all I've got is getting the file name and checking it exists.</p>
  
  <pre><code>int main()
  {
      //Get file names
      string studentsFile, resultsFile, line;
      cout &lt;&lt; "Enter the Students file: ";
      getline(cin, studentsFile);
      cout &lt;&lt; "Enter the results file: ";
      getline(cin, resultsFile);
  
      //Check for students file
      ifstream students_stream(studentsFile);
      if (!students_stream) {
          cout &lt;&lt; "Unable to open " &lt;&lt; studentsFile &lt;&lt; "\n";
          return 1;
      }
  }
  </code></pre>
  
  <p>I tried using getline with 3 arguments and " " as the delimiter but that would also split the name part of the string, so I'm not sure how to do this another way.</p>