Results 1 to 4 of 4

Thread: ofstream: checking size of associated file <resolved>

  1. #1

    Thread Starter
    Hyperactive Member Comreak's Avatar
    Join Date
    Feb 2001
    Location
    Dis
    Posts
    319

    Question ofstream: checking size of associated file <resolved>

    How can I peak at the data inside an ofstream object when it's associated with a file? I want to do this so I can make sure that the data inside a file can be stored inside a buffer (char string) safely. Thanks.

    EDIT:// brevity
    Last edited by Comreak; Jul 13th, 2003 at 02:25 PM.

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Keep reading it into blocks of a fixed size (say 8K), eventually you'll read less than your buffer size, and you know you've hit the end.

    Alternatively, use stat() on the file before you open it to find out its size.
    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
    Hyperactive Member Comreak's Avatar
    Join Date
    Feb 2001
    Location
    Dis
    Posts
    319
    Originally posted by parksie
    Keep reading it into blocks of a fixed size (say 8K), eventually you'll read less than your buffer size, and you know you've hit the end.

    Alternatively, use stat() on the file before you open it to find out its size.
    Stat() sounds like a good way to do what I want to do. I'm a bit confused though; how would someone go about using stat()?

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Read the documentation, MS even have a sample program on MSDN.
    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

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