How do I write this code that reads & counts the number of lines & characters in a file?

Here is my function code, but apparently I screwed up big time, what the heck do I type? I am desperate. My friend told me there is a way to use a while loop and use a getline but I don't know how to do that, but apparently I don't know how to do it this way either.

// Function: countCharsLines
void countCharsLines(ifstream &inFile, int &countLines, int &countChars)
{
// Variables
int countLines = 0;
int countChars = 0;
string counter;

while (!eof)
{
inFile >> counter;
countLines++;
countChars += counter;
}
}
but apparently I screwed up big time


What makes you say that?

Does the code error when you try to compile it? If yes, tell us the error.

Does it compile but not do what you want? Tell us what it's doing and what you want it to do.


It's much easier to solve a problem when we know what the problem is. Be descriptive.
Oh nevermind LoL I found an easier method. Thanks anyway.
Topic archived. No new replies allowed.