Off topic, but in the spirit of trying not to learn bad habits, and trying to avoid bugs that can be difficult to find when trying to determine why you don't get the results you expect on trial runs with known input as you test your code, the following
while (! infile.eof())
{
ch = cin.get();
could be changed to
while(infile >> ch)
You should avoid using the return value of eof() as the controlling condition for a loop. There are two reasons I know of to want to do this.
First, using the return value of eof() to terminate the loop is likely to cause a double counting of the last char in the file. If that char is a newline, then the double count will go unnoticed in your current code. But if the file terminates with an alphabetical char, it may, or may not, be counted twice. Inmy experience, trying to figure out why the code works appropriately sometimes and not others is probably the hardest bug to find.
Second, using the return value of the input statement to control the loop allows the loop to terminate appropriately, whether it terminates becuase it read the entire file, or whether it terminates because of some other cause. The loop might not terminate appropriately if the control condition is only whether the EOF marker was found but the linput stream fails for some other reason.