Skip to main content

在C++里得到一个文件大小的方法

技术
Author

cookwhy

Published

June 3, 2009

在C++里读出文件大小的方法,示例代码如下:

#include
#include
using namespace std;

int main () {
long begin,end;
ifstream myfile (“example.txt”);
begin = myfile.tellg();
myfile.seekg(0, ios::end);
end = myfile.tellg();
myfile.close();
cout << “size is: ” << (end-begin) << ” bytes.”;
return 0;
}