There is a problem in:
while(std::getline (file,line)){
if (! isblank(line)){
// now the variable string "line" contains the line content
file >> first_name;
file >> last_name;
file >> age;
}
Once you complete the getline you already have the 3 values in variable line
but you never use it. You are doing a second read... so you are ignoring half the lines in your input.
What you should do instead is:
while(file >> first_name >> last_name >> age)
{
//do whatever you want to do with age in here
}
This loop will end if you are unable to read a sequence 2 strings and 1 number, either due to reaching the end of file or illformed input.
By reading like this you don't need the isblank
method.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…