ios::cur

This is a discussion on ios::cur within the C++ Programming forums, part of the General Programming Boards category; How come infile.eof() is never true in this example? I am stuck in an infinite loop... but I know that ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    12

    ios::cur

    How come infile.eof() is never true in this example? I am stuck in an infinite loop... but I know that the size of input.txt is only 100bytes.


    Code:
    ifstream infile("input.txt", ios::in);
    while (!infile.eof())
    {
        infile.seekg(1, ios::cur);
    }

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,793
    You can try putting in a call to tellg in the loop and see if/how the get pointer is moving. If it keeps giving you the same value back, something is wrong.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    12
    No, I put in a cout << tellg() and that keeps increasing by one, but it never stops.. why?

  4. #4
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    You can move the file pointer all you like, but if you never attempt to read from the file, eof will never get set.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. class inheritence with constructor parameters
    By drdodirty2002 in forum C++ Programming
    Replies: 3
    Last Post: 06-20-2005, 06:49 PM

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