Default User ha scritto:[color=blue]
> Cingar wrote:[color=green]
> > Gianni Mariani ha scritto:[color=darkred]
> > > // get length of file:
> > > ifstream file;
> > > file.open( "file.nome", ios::binary );
> > > file.seekg( 0, ios::end );
> > > int length = file.tellg();[/color]
> >
> > &, in C:
> >
> > #include <stdio.h>
> > FILE * file;
> > file = fopen("file.name", "rb");
> > fseek(file, 0, SEEK_END);
> > long length = ftell(file);[/color]
>
> Also not guaranteed to work.[/color]
Of course. As the two code fragments are just different syntactic flavors
for exactly the same stuff, either both are guaranteed to work, or both
aren't. :-)
However, I think this is the best approximation you can have with standard
C and C++ libraries.
IMHO, a solid program should use more reliable non-portable API's, and
leave this approach as the default portable implementation. I.e., the
fseek/ftell implementation could be a pretty good #else in a cascade of
platform-specific #elif's.
--
Cingar
--
questo articolo e` stato inviato via web dal servizio gratuito
http://www.newsland.it/news segnala gli abusi ad
abuse@newsland.it