Input file pointer manipulation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • prybrr04
    New Member
    • Oct 2007
    • 1

    #1

    Input file pointer manipulation

    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)
    [code=cpp]
    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);
    [/code]
    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!
    Last edited by sicarie; Oct 9 '07, 12:39 PM. Reason: Code tags
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Originally posted by prybrr04
    (the class declaration)
    You seekg to the value returned by tellg. Your next read will start there.

    Comment

    Working...