Complicated reading from file

I've searched this forum and the internet quite a bit and I'm still not exactly clear how I would go about doing this.
I tried using fstream and getline to read text from a file, however I don't think I fully understand how I would apply it to this approach. My goal is to store this data into a 100 int array memory[].

In my text file, I have comments start with **, and that should make the program ignore that line.

An example of a normal line is:
00 +1099

The 00 is the array location where this data should be stored. The plus can be ignored I think, and the 1099 is to be stored in the array.

Later on in the program I would read the first two digits (10) and execute something off of them, while the last two (99) would be the array location modified.
If anyone is wondering, this is for the simpletron program from the deitel books.
I would really appreciate some help in this matter, as I'm a bit lost. I understood it in java but that was a long time ago and I can hardly remember it...
Thanks!
(By the way, this is school related, however I don't want a solution, I just am trying to figure out how I would go about doing the operations I listed above)
Last edited on
To read a number, use operator >>. If there is no number in the file, >> will fail.
When it fails, my_file.fail will return true. You'll have to call my_file.clear before any input operations.
To ignore a line you can either getline it into a garbage string or (more appropriate) use my_file.ignore(numeric_limits<streamsize>::max(), '\n');
Topic archived. No new replies allowed.