转自http://www.codeproject.com/useritems/filesize.asp
#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;
}
#include <sys\types.h>
#include <sys\stat.h>
int FileSize( const char * szFileName )
{
struct stat fileStat;
int err = stat( szFileName, &fileStat );
if (0 != err) return 0;
return fileStat.st_size;
}
#include <fstream>
int FileSize(const char* sFileName)
{
std::ifstream f;
f.open(sFileName, std::ios_base::binary | std::ios_base::in);
if (!f.good() || f.eof() || !f.is_open()) { return 0; }
f.seekg(0, std::ios_base::beg);
std::ifstream::pos_type begin_pos = f.tellg();
f.seekg(0, std::ios_base::end);
return static_cast<int>(f.tellg() - begin_pos);
}
#include <boost/filesystem/operations.hpp>
boost::intmax_t file_size( const path & ph );
本文地址:http://com.8s8s.com/it/it359.htm