Newsgroup: it.comp.lang.c
Titolo: sizeof

salve.
per favore rispondete alla mia domanda:
Come faccio a ottenere le dimensioni di un file?(con c/c++)
risp presto
grazie



 Come faccio a ottenere le dimensioni di un file?(con c/c++)
   // get length of file:
   ifstream file;
   file.open( "file.nome", ios::binary );
   file.seekg( 0, ios::end );
   int length = file.tellg();
?

 wrote in comp.lang.c++:

Not guaranteed to be correct, although it works on most platforms.
-- 
Jack Klein
Home: 
http://JK-Technology.Com
FAQs for
comp.lang.c 
http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ 
http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html


What exactly can be incorrect?
-- 
 Alex Vinokur
     email: alex DOT vinokur AT gmail DOT com
 
http://mathforum.org/library/view/10978.html
 
http://sourceforge.net/users/alexvn

 What exactly can be incorrect?
The result of trying to seek to the end of a binary file is undefined.

 wrote in message news:cu4srt$dpk$00$2...@news.t-online.com...

1. What is a reason for that?
2. Can we have any indication of that?


 per favore rispondete alla mia domanda:
Per cortesia, non fare uso del cross-post.
Posta la tua domanda in it.comp.lang.c++ (in italiano), oppure in
comp.lang.c++ (in inglese), se vuoi una risposta relativa al C++, oppure
in it.comp.lang.c (in italiano) o in comp.lang.c (in inglese) se vuoi una
risposta relativa al C.
-- 
questo articolo e` stato inviato via web dal servizio gratuito 
http://www.newsland.it/news
 segnala gli abusi ad 
ab...@newsland.it

    int length = file.tellg();
&, in C:
#include <stdio.h>
FILE * file;
file = fopen("
file.name
", "rb");
fseek(file, 0, SEEK_END);
long length = ftell(file);
--
Cingar


 long length = ftell(file);
Also not guaranteed to work.
http://www.eskimo.com/~scs/C-faq/q19.12.html
Brian

 Also not guaranteed to work.
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.


 
http://www.eskimo.com/~scs/C-faq/q19.12.html
IMHO that FAQ entry is not very clear. 
"ftell is not guaranteed to return a byte count except for binary files."
It seems that I _can_ fopen() the file as "b", fseek() to the end and then use
ftell().
That sentence should be something like that:
"ftell is not guaranteed to return a byte count except for binary files,
but in this case you can't fseek to the end of the file since fseek
needn't support SEEK_END on binary streams."
Luca
-- 
Home: 
http://kronoz.cjb.net
The trouble with computers is that they do what you tell them, 
not what you want.
D. Cohen

 
What happens if we have no READ privilege on this particular files? Is 
this the issue?

 2. Can we have any indication of that?
I don't know if it's the same for C++, for C language Standard
ISO/IEC 9899:1999 states
"A binary stream need not meaningfully support fseek calls with a
whence value of SEEK_END."
C:\>iao Angelo
-- 
Posted via Mailgate.ORG Server - 
http://www.Mailgate.ORG

 this the issue?
With this technique, you need to open the file. If you don't have READ
privilege you can't open file.
HTH
