The only guaranteed, portable way to get the number of characters that
your program can read from a file is to read them and count them.
There might or might not be platform specific extensions that your
compiler/operating system combination supplies. You would need to ask
in a platform specific support group for that.
But even then, there is no guarantee that the value provided by that
function will equal the number of characters that you can read from
the file, especially in text mode.
Hi Jack,
I'm sure this has come up a lot, but I don't have the complete picture in
my head (and scouring the library spec hasn't given me an answer yet), so
I'm wondering if I can impose on you to explain it in this context: If you
know a stream represents a binary file (let's not worry about text files
and the associated platform-specific CRLF handling), is there a
standard/portable way to perform the moral equivalent of:
1. ftell to get the current position
2. fseek to the end
3. ftell to get the file size
4. fseek back to where you started
in order to find out the file size? I found protected functions of
basic_filebuf to do various kinds of seeking, and rdbuf() to supposedly get
access to the basic_filebuf in order to try to invoke them, but I ran into
access violations trying to use those functions (they're protected, at
least in the Dinkumware implementation).
Thanks!
-leor