[nfbcs] Failing If Statement

Mike Gorse mike at straddlethebox.org
Fri Oct 27 18:11:01 UTC 2017


Hi Lanie,

I'm guessing that these lines are what you're referring to:

    if (fin.fail());
       cout << "Error reading file \"" << fileName << "\"\n";

You have a ; at the end of the if clause. You don't want a ; at the end of 
the line; it will make the if clause do nothing, and the following line 
will be executed unconditionally.

If you pass -Wall to g++, then it will print a warning (or at least it 
will with the version that I have installed).

Hth,
-Mike

On Fri, 27 Oct 2017, Lanie Molinar via nfbcs wrote:

> Hi, everyone. Thanks for your help again last night. If you don't mind, I 
> have another question. I'm working on another assignment and have almost 
> everything worked out, but one of my if statements is acting weird, and I 
> can't figure out why. It's reporting an error when it shouldn't be. I've gone 
> over my code several times, and everything seems fine to me. Can someone 
> please take a look? The grades.txt file I attached is used by my program. 
> Thanks.
>
>




More information about the NFBCS mailing list