From: lsantil AT calstatela DOT edu Date: Fri, 19 Jun 1998 01:01:54 -0700 (PDT) To: Nate Eldredge cc: djgpp AT delorie DOT com Subject: Re: Get file size in C++ In-Reply-To: <3589B9CF.AC9FDAE4@cartsys.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Precedence: bulk On Thu, 18 Jun 1998, Nate Eldredge wrote: > lsantil AT calstatela DOT edu wrote: > > > > How is it possible to get the size of a file in C++? I know if I opened > > a file in C w/ "FILE *f;" that I just include "io.h" & use printf to print its > > size from the return val of "filelength(fileno(f))" but I'm using ifstream & > > "fstream.h" to open my files. I looked thru the "lang/cxx/" dir & found > > "iostdio.h" which makes some of the "stdio.h" defines equivalent to _IO_* > > including "#define fileno _IO_fileno" //line 107// but I dont see how I can > > do the same with "ifstream f". any suggestions? > > It looks like there's a member function of one of the classes from which > `ifstream' is derived called `fd', which returns the file descriptor > (aka handle) of the stream. You can then pass that to `filelength' et > al. I'm not sure of the C++ syntax; it might be something like > `f.fd()'. You were close Nate. I looked thru the fstream.h(I after your gave me a hint at what to look for) & noticed the member f.filedesc() which does return the file number/file descriptor which you can pass to fiellength. BTW, is there a builtin member that is defined somewhere so that I can just do something simple like this "cout << f.filelength();" & so that I dont have to include io.h? > > -- > > Nate Eldredge > nate AT cartsys DOT com > >