File Input Question

This is a discussion on File Input Question within the C++ Programming forums, part of the General Programming Boards category; Hi, I have a text file that looks like this:
<file>
POV Scene Description File
Starting value of t:
0
...

File Input Question

Hi, I have a text file that looks like this:
<file>
POV Scene Description File
Starting value of t:
0
Ending value of t:
6.28
Number of balls:
200
</file>
Anyways, I have to read in certain parts of the file. Specifically, 0, 6.28, 200. The rest is stuff I don't need but it's required that I read in only those values. All of my program is ready to go and to test, I've simply had it set up like this "0 6.28 200" but I have to change it so it looks like the example above and I have no idea. Heh, I tried this

Code:

input >> variable >> variable >> variable;

for example, with input being my fstream variable but that of course did not work, I really have no idea what to do as getline is for strings so I'm stumped. Anyhelp will be appreciated. Also for your information, I am using fstream. Thanks

The cin.ignore() line is necessary or the subsequent getline() attempt will get messed up. getline() stops reading when it encounters a '\n', and the >> operator leaves the '\n' in the input stream. So, after this line is executed:

inFile>>start;

there will still be a '\n' sitting in the input stream as the next character to be read, so getline() will only read that character and then end, but you need it to read in the whole next line. The solution is to use cin.ignore(), which skips one character.

If the numbers could be on any line in the file, then you have to read in each line as a string, test for an alpha numeric character at the first position, if there isn't one--discard the string, if there is one and you need to use it in a numerical calculation, you need to convert it to a number using a function like atoi() (-->alpha to int).