Results 1 to 3 of 3

Thread: problem with fstream's eof

  1. #1

    Thread Starter
    Lively Member dubae524's Avatar
    Join Date
    Jun 2001
    Location
    Currently on this Super Star Destroyer being telekinetically strangled to death by Darth Vader
    Posts
    78

    problem with fstream's eof

    Hi everyone.

    I am using code like this:

    while(!ifs.eof())
    cout << hex << ifs.get() << '\n';

    The file that I am using has exactly 283,858 bytes (i.e. it is fairly large); however, the thing thinks the last character is character #21,018, because that's when ifs.eof() returns true. Can anyone help me out here? Can anyone tell me to make it _know_ that the last character is at character #283,857? Thanks.
    - Justin Patrick Butler

    Comme je trouve. "As I find."
    - Butler family quote

    Beneficia sumptos procul superant. "The benefits far exceed the costs."
    - Myself

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    What type of file is it - is it binary? If it is you need to make sure you're opening the stream as ios::binary.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3

    Thread Starter
    Lively Member dubae524's Avatar
    Join Date
    Jun 2001
    Location
    Currently on this Super Star Destroyer being telekinetically strangled to death by Darth Vader
    Posts
    78
    Yes that was the problem!

    Thank you!
    - Justin Patrick Butler

    Comme je trouve. "As I find."
    - Butler family quote

    Beneficia sumptos procul superant. "The benefits far exceed the costs."
    - Myself

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width