Understanding the effects of loops and such

I am confused.....If I comment out the getline statement in the snippet below, (the getline before the "while" statement) it changes the number of lines returned by the while statement.

Ex....actual number of text lines in the text file may be 6 but with the getline function included, it will return 5 lines.

I guessing that it is reading the number of lines after the getline function is initiated?

I don't really need it but I was experimenting and it confused me so I figured I would ask.

//--------GetStudentList
string GetStudentList()
{
ifstream inputFile;
string File1;
int NumberOfLines = 0;
cout <<"Enter the file name for the list of Students, including the extension::" << endl;
getline(cin, File1);
inputFile.open(File1.c_str());
if(!inputFile.is_open())
{
exit(EXIT_FAILURE);
}
getline(inputFile, File1);
cout << File1 << endl;
while (getline (inputFile, File1))
{
++NumberOfLines;
}
cout << "Number of Lines in text file is: " << NumberOfLines << endl;
cout << "\nThe file has been successfully opened for reading.\n";

return File1;
}//end GetStudentList
//--------GetClassHours
string GetClassHours()
{
ifstream inputFile;
string File2;
cout <<"Enter the file name for the list of Class Hours, including the extension::" << endl;
getline(cin, File2);
inputFile.open(File2.c_str());
if(!inputFile.is_open())
{
exit(EXIT_FAILURE);
}
cout << "\nThe file has been successfully opened for reading.\n";
return File2;
}//end GetClassHours
if you have 6 apples and you eat one, ¿how many remain?
So my quess is correct...? Since I basically read the first line, the count stated at the second line....
the while checks the condition within its inner scope .
Topic archived. No new replies allowed.