title: Using getline() with file input in C++
body: <p>I am trying to do a simple beginner's task in C++. I have a text file containing the line 
  "John Smith 31". That's it. I want to read in this data using an ifstream variable. But I want to read the name "John Smith" into one string variable, and then the number "31" into a separate int variable.</p>
  
  <p>I tried using the getline function, as follows:</p>
  
  <pre><code>ifstream inFile;
  string name;
  int age;
  
  inFile.open("file.txt");
  
  getline(inFile, name); 
  inFile &gt;&gt; age; 
  
  cout &lt;&lt; name &lt;&lt; endl;
  cout &lt;&lt; age &lt;&lt; endl;  
  
  inFile.close();    
  </code></pre>
  
  <p>The problem with this is that it outputs the entire line "John Smith 31". Is there a way I can tell the getline function to stop after it has gotten the name and then kind of "restart" to retrieve the number? Without manipulating the input file, that is? </p>