使用C ++ filestreams(fstream),你如何确定文件的大小? [英] Using C++ filestreams (fstream), how can you determine the size of a file?
本文介绍了使用C ++ filestreams(fstream),你如何确定文件的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我确定我刚刚在手册中错过了这一点,但是如何使用C ++的 istream
类来确定文件的大小(以字节为单位) fstream
头?
I'm sure I've just missed this in the manual, but how do you determine the size of a file (in bytes) using C++'s istream
class from the fstream
header?
推荐答案
c $ c> ios :: ate 标志(和 ios :: binary
标志),因此 tellg / code>函数将直接给你的文件大小:
You can open the file using the ios::ate
flag (and ios::binary
flag), so the tellg()
function will give you directly the file size:
ifstream file( "example.txt", ios::binary | ios::ate);
return file.tellg();
这篇关于使用C ++ filestreams(fstream),你如何确定文件的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文