PeteOlcott
10/6/2008 2:34:00 PM
On Oct 6, 5:21 am, James Kanze <james.ka...@gmail.com> wrote:
> On Oct 5, 6:21 pm, Victor Bazarov <v.Abaza...@comAcast.net> wrote:
>
> > Peter Olcott wrote:
> > > Is there any standard C++ way to determine the size of a
> > > file before it is read?
> > No. The "standard C++ way" is to open the file for reading,
> > seek to the end of the file and get the position.
>
> That's a frequently used method, but it certainly isn't standard
> C++. There's no guarantee that the position is convertable to
> an integral type, and there's no guarantee that the integral
> value means anything if it is.
>
> In practice, this will probably work under Unix, and with binary
> (but not text) files under Windows. Elsewhere, who knows?
Why would it not work for Text files under Windows?
(I am only looking for the size that can be block read into memory)
>
> > If you need the size of the file on disk (and you have the
> > name of the file) without "touching" is in any way, use the
> > existing platform (OS) mechanisms to get the "file stats"
> > (statistics). RTFM on programming your OS.
>
> Supposing, of course, that the system has some sort of request
> for determining what you mean by file size. The most obvious
> meaning is the number of bytes you will read before encountering
> EOF. And as far as I know, Unix is the only system which has a
> request which will return this. Another reasonable meaning is
> the number of bytes the file occupies on the disk, but I don't
> know of any system which has a request for this. (Unix
> certainly doesn't.)
>
> --
> James Kanze (GABI Software) email:james.ka...@gmail.com
> Conseils en informatique orientée objet/
> Beratung in objektorientierter Datenverarbeitung
> 9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34