what should i do when .....(read/write txt file problem)

This is a discussion on what should i do when .....(read/write txt file problem) within the C++ Programming forums, part of the General Programming Boards category; Dear All, i have a txt file which have the following data: data1 data2 (new line but with nothing type,i.e. ...

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    117

    what should i do when .....(read/write txt file problem)

    Dear All,

    i have a txt file which have the following data:

    data1
    data2
    (new line but with nothing type,i.e. the cursor can move to this line)

    i discover that when the point moved to the third line, i cant get back to the beginning of the file even i use file.seekg(0,ios::beg)
    while i can when the pointer never reach line 3.
    here is my code and output if you dun understand:

    [code]
    cout << file7.tellg() << endl;
    file7.ignore(500,'\n');
    file7.ignore(500,'\n');
    file7.getline(RFQ,14);
    cout << "||" << RFQ << "||" <<endl;
    file7.seekg(0,ios::beg);
    cout << file7.tellg() << endl;
    file7.getline(RFQ,14);
    cout << "||" << RFQ << "||" <<endl;
    file7.seekg(0,ios::beg);
    cout << file7.tellg() << endl;
    file7.close();
    [\code]

    output:
    0
    ||||
    0
    ||||
    0

    how to solve the situation??
    thanks!!

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    117

    use file.clear()

    to those who are interested in this thread:

    problem solved.
    use file.clear();

    thank you~~~

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need Help Fixing My C Program. Deals with File I/O
    By Matus in forum C Programming
    Replies: 7
    Last Post: 04-29-2008, 07:51 PM
  2. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  3. Replies: 3
    Last Post: 03-04-2005, 01:46 PM
  4. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 09:46 AM
  5. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 02:58 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21