Hello, I am trying to read a file and take the average of the sum of grades and display the average. I am able to do that just fine, but I am just trying to figure out how to error check. If there is more or less than 10 grades in the file I am pulling from I want it to say "Error reading file from" fileName, but I am having a hard time understanding the syntax of the fin.fail? Where would I put the condition, before the statement "Error reading... " Here is my code below, sorry I tried to search for this but I feel like everything is just fin.fail() and it seems like that's just such a general statement and I just want to know how the computer knows when it should fail opening the file.
std::ios::fail() isn't really used for what you think it's used for, I don't think. Your arbitrary restriction on how many lines a "valid file" should have has no bearing on whether or not the stream is in a certain state or not.
For what you're trying to achieve, you can simply read the file line-by-line. Push each line onto a vector, then compare the size of the vector against some desired, fixed size.