Part of my homework deals with reading floating-point values from a text file, and then outputting them. As such, I have two "float" variables into which data from my ifstream is supposed to be read. However, that is not happening. My stream did not fail. The text file itself just contains:
180.5 200
I'm coding the program in a virtual machine, though, so I'll have to log into the forums via the VM to paste the code.
The file appears to be opening just fine. Oh, and after the >> line, studentScore is -0 and totalPossibleScore is some big, negative number. Except when I initialize it to 0 in the declaration line, in which case it's 0.
contents of file:
-1.#IND
first number: -1
input of second number failed
------------------
contents of file:
180.5 200
first number: 180.5
second number: 200
OK, so I now noticed that I have an error in my file path. Instead of "Lab 4" the folder should have been "Lab 2" Running that, I get my "could not open" error & abort. Strange thing - I'm using a USB disk drive at E, there is no "Lab 4" folder, so the program should have complained then, not now.
Edit: It appears the problem was with my path. You see, the string was hardcoded like this:
E:\CIS 022\Lab 2\Files\studentGrade.txt
when I should have written this:
E:\\CIS 022\\Lab 2\\Files\\studentGrade.text
Edit: It works up to a point. I mean, I run it one time, it outputs 9.5 and 1.#INF. Second time, like 1.#INF and -1.#IND0
Edit #2: The 9.5 is because I changed the 180.5 to 9.5.