Use this:
fin.get(ch);
in place of the fin >> ch;
line. For additional details, check out: std::basic_istream::get. To be absolutely sure the ch
variable has new content, use the fail()
method before any processing (e.g. reference: std::basic_ios::fail). An example:
if ( isalpha(ch) && !fin.fail())
{
.
.
.
The basic fstream reference is here: std::basic_fstream.