您可以在这里快速查找:


 
您的位置: 编程学习 > C++/VC > 200602
文章分类

Java技术
2005: 03 04 05 06 07 08
09 10 11 12
2006: 01 02

Asp.net
2005: 07 08 09 10 11 12
2006: 01 02

VB编程
2006: 02

Asp编程
2005: 11 12
2006: 01 02

C++/VC
2005: 10 11 12
2006: 01 02

Delphi
2005: 12
2006: 01 02

其它

 本文章适合所有读者

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

xflytang
转自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 );