Connecting Tech Pros Worldwide Forums | Help | Site Map

Input file pointer manipulation

Newbie
 
Join Date: Oct 2007
Posts: 1
#1: Oct 9 '07
Hello All,

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
  1.  if (myfile.is_open())
  2.     {
  3.        while (! myfile.eof() )
  4.        {
  5.  
  6.          myfile.seekg (7);
  7.          rows = myfile.tellg();
  8.          cout << "The number of rows: " << rows << endl;
  9.  
  10.          myfile.seekg(15);
  11.          columns = myfile.tellg();
  12.          cout << "The number of columns: " << columns <<endl;
  13.  
  14.          myfile.seekg(31);
  15.          PlayerA = myfile.tellg();
  16.          cout << "Player A has a score of: " << PlayerA << endl;
  17.  
  18.          myfile.seekg(33);
  19.          PlayerB = myfile.tellg();
  20.          cout << "Player B has a score of: " <<PlayerB << endl;
  21.  
  22.          myfile.seekg(0, ios::end);
  23.  
The problem is I get the pointer position, which is correct because tellg() returns the pointer position. How can read the value in the pointer position? Any suggestions are welcome. TIA!

Moderator
 
Join Date: Mar 2007
Location: North Bend Washington USA
Posts: 5,375
#2: Oct 9 '07

re: Input file pointer manipulation


Quote:

Originally Posted by prybrr04

(the class declaration)

You seekg to the value returned by tellg. Your next read will start there.
Reply