This question already has an answer here:
My question is simple:
Should I use fseek with SEEK_END to get to the end of a file and then get the length of it ? Because in the man it is said:
- Library implementations are allowed to not meaningfully support SEEK_END (therefore, code using it has no real standard portability).
Right now I am using stat (from C) which is better ?
Since C++ inherits
fseek
andSEEK_END
from C, I'm quoting the C standard here:The
ftell
function returns a long, which means that on an ILP32 system you can't correctly get the size of a file larger than 2GB. You should use thestat
function or similar to get the size of a file; check the manual for the operating system you're targeting in case you have use a different function name (stat64) or define a preprocessor macro to get the desired behavior for large files.