Quick and Dirty Series: C ++ FileSize () FUNCTION

xiaoxiao2021-03-06  40

Transferred from

http://www.codeproject.com/UserItems/filesize.asp

#include

#include

__INT64 FILSIZE64 (const char * szfilename)

{

Struct __stat64 fileestat;

Int err = _stat64 (szfilename, & fileestat);

IF (0! = Err) Return 0;

Return FileStat.st_size;

}

#include

#include

Int filesize (const char * szfilename)

{

Struct stat Filestat;

Int err = stat (szfilename, & fileestat);

IF (0! = Err) Return 0;

Return FileStat.st_size;

}

#include

Int filesize (const char * sfilename)

{

Std :: ifstream f;

F.Open (sfilename, std :: os_base :: binary | std :: ios_base :: in);

IF (! f.good () || f.eof () ||! f.is_open ()) {return 0;}

F.seekg (0, std :: os_base :: beg);

Std :: ifstream :: pOS_TYPE BEGIN_POS = f.tellg ();

F.seekg (0, std :: os_base :: end);

Return static_cast (f.TELLG () - Begin_pos);

}

#include

Boost :: INTMAX_T FILE_SIZE (Const Path & P);

转载请注明原文地址:https://www.9cbs.com/read-78034.html

New Post(0)