I wanted came here to get some advice on reading an input file where I will have to ignore some of the text. Here is the sample text file:
SIZE: 4 ROWS, 4 COLUMNS
SCORE: 0 0
----
----
----
----
For now, I'm just trying to read the integers on the first and second line. The next step is reading the "-" into a 2-D array that I have declared, but I haven't gotten that far yet. (However, if anyone has any hints how to read this into a 2-D they are readily welcome!)
Here is my code for reading the input file: (just a snippet of code in my main function)
Expand|Select|Wrap|Line Numbers
- if (myfile.is_open())
- {
- while (! myfile.eof() )
- {
- myfile.seekg (7);
- rows = myfile.tellg();
- cout << "The number of rows: " << rows << endl;
- myfile.seekg(15);
- columns = myfile.tellg();
- cout << "The number of columns: " << columns <<endl;
- myfile.seekg(31);
- PlayerA = myfile.tellg();
- cout << "Player A has a score of: " << PlayerA << endl;
- myfile.seekg(33);
- PlayerB = myfile.tellg();
- cout << "Player B has a score of: " <<PlayerB << endl;
- myfile.seekg(0, ios::end);