这个问题在这里已经有了答案:
How can I get a file's size in C++? [duplicate]
(7 个回答)
3年前关闭。
我确定我刚刚在手册中遗漏了这一点,但是如何使用来自 istream
header 的 C++ 的 fstream
类来确定文件的大小(以字节为单位)?
最佳答案
您可以使用 ios::ate
标志(和 ios::binary
标志)打开文件,因此 tellg()
函数将直接为您提供文件大小:
ifstream file( "example.txt", ios::binary | ios::ate);
return file.tellg();
关于c++ - 使用 C++ 文件流 (fstream),如何确定文件的大小?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2409504/