2010-09-22, 01:41 PM
Well there are basically 3 parts to reading a file...
1) open a file handle so it knows which file to look at
2) read the characters of the file (since it's a text file you basically can treat the file as one long string, starting reading from the top), convert it to format you want (double, char, etc.)
3) close the file when it hits the end
These are fairly common tasks so most languages make them easy, it is still a little complicated to allow flexibility but you can pretty much distinguish between the 3 steps. Just be happy you're not using Java, and don't have to wrap file i/o in try/catch statements.
In simple text files part 2 is taken care of by getline() - which takes the next line - and then splitting it up (into tokens) - and then converting tokens to the type you want, which seems to be double (so strtod).
1) open a file handle so it knows which file to look at
2) read the characters of the file (since it's a text file you basically can treat the file as one long string, starting reading from the top), convert it to format you want (double, char, etc.)
3) close the file when it hits the end
These are fairly common tasks so most languages make them easy, it is still a little complicated to allow flexibility but you can pretty much distinguish between the 3 steps. Just be happy you're not using Java, and don't have to wrap file i/o in try/catch statements.
In simple text files part 2 is taken care of by getline() - which takes the next line - and then splitting it up (into tokens) - and then converting tokens to the type you want, which seems to be double (so strtod).

