I was wondering how one might go about the following:
I am reading in data from a file using getline(inputFile, tempString)
. Some of this information has to stay in string format, and other information must be converted to floats, ints, etc.
I anticipate there being a problem if there is an error in the file and one of the pieces of data that should be read into an int is read into a string. For instance, if there were a file as follows:
100 should be read and converted to int
100.23 should be read and converted to a float
100 spring ln should be read and stay a string
Michael should be read and stay a string
101 should be read and converted to int
100.50 should be read and converted to float
101 spring ln should be read and stay a string
100.58 should be read and stay a string --- WOULD CREATE A NOT SO OBVIOUS ERROR
102 spring ln should be read and converted to int --- OBVIOUS ERROR
Steven should be read and converted to float --- OBVIOUS ERROR
the code that is reading the file is a loop until EOF. Is there any way to check for the not so obvious error?