How to calculate file size in c++


The solution is not portable, it works only with Visual Studio c++.


#include <sys\types.h>
#include <sys\stat.h>
__int64 FileSize64( const char * szFileName )
{
struct __stat64 fileStat;
int err = _stat64( szFileName, &fileStat );
if (0 != err) return 0;
return fileStat.st_size;
}



The advantage of using this function here is that there is no need to open a file prior to calculating it's size. But it rather seems unlikely :)

Post a Comment

Previous Post Next Post