7Stud, that doesn't work for all problems of this type; you want to do the next read just before the end of the loop for a generic case. The following could work:
Code:
fIn.get(ch);
while(!fIn.eof()) {
++x;
fIn.get(ch); // The last line before the end of the loop
}
But it's simply easier to use the comma operator in the while() loop; it saves having to duplicate the fIn.get() line, and it ensures that the check for EOF is immediately after the get(). I still prefer to use my original suggestion:
Code:
while(fIn.get(ch), !fIn.eof()) {
++x;
}
but that is equivalent to the modified version of your code.
BTW, if the goal is to get the size of a file, there are a lot faster ways to do it, look for seek methods, and seek to "zero bytes before the end of the file", then use a tell method to get the current position in the file.