title: C++ getline multiple variable types using comma as delimiter
body: <p>I'm trying to do a home work assignment which requires data fro a txt file to be read in to variables. The file has this on each line "surname, initials, number, number". I have got the get line working partially using the following code.</p>
  
  <pre><code>    ifstream inputFile("Students.txt");
  string line;
  
  string Surname;
  string Initial;
  int number1, number2;
  
  while (getline(inputFile, line))
  {
      stringstream linestream(line);
  
      getline(linestream, Surname, ',');
      getline(linestream, Initial, ',');
      getline(linestream, number1, ',');
      getline(linestream, number2, ',');
  
      cout &lt;&lt; Surname &lt;&lt; "---" &lt;&lt; Initial &lt;&lt; "-" &lt;&lt; number1 &lt;&lt; "-" &lt;&lt; number2 &lt;&lt; endl;
  
  }
  </code></pre>
  
  <p>This throws a compile error, but if I declare number1 and number2 as strings it works fine. So my question is, do I have to getline as a string then convert to an int variable or is there a better way?</p>