Your line 11 will read and store the number, but it won't remove the newline character from the stream afterwards. Thus, the following getline will read the rest of the line ... which is empty.
I think the 'ignore' statement below will work (100 is just allowing for a few blanks):
#include<iostream>
#include<fstream>
#include<sstream>
#include<string>
usingnamespace std;
int main()
{
string found = "Student";
string line, address;
string dummy;
int number;
ifstream fin( "list.txt" );
while( getline( fin, line ) ) // read a line from the file
{
if ( line.find( found) != string::npos ) // check if it contains the text in 'found'
{
stringstream ss( line ); ss >> dummy >> number; // stream this line into a dummy variable and number
getline( fin, address ); // next line should be address
cout << "Student number: " << number << " Address " << address << endl;
}
}
}
Both produce
Student number: 1001 Address 25 Bedford St. New York City, N.Y. 10014
Student number: 1002 Address 125 Maiden Lane, 11th Floor New York, NY 10038