void lineNum(string fileName, ifstream& myFile)
{
int lineNum=0;
char ch=0;
while (!myFile.eof())
{
myFile.get (ch);
if(ch=='\n')
lineNum++;
}
cout << "Excellent! The number of lines in " << fileName << "is ---> ";
cout << lineNum << endl;
}
My question is a concern within this function. The program runs, and keeps returning +1 lines than there are in the text file. I noticed within the file, the cursor when at EOF is on a new line without text.
i.e.
giughreuig rgiuhrgh (\n)
ergj rueighre e guhegu (\n)
.....
rvgfrfeff gfuf f gfufuf (\n)
EOF
rather than
giughreuig rgiuhrgh (\n)
ergj rueighre e guhegu (\n)
.....
rvgfrfeff gfuf f gfufuf (\n)EOF
I don't feel right doing a lineNum-- at the end of the code.
Any suggestions???