让我们为这个问题提出一个补充问题。在C ++中获取文件大小的最常用方法是什么?在回答之前,请确保它是可移植的(可以在Unix,Mac和Windows上执行),可靠,易于理解且没有库依赖性(没有boost或qt,但是例如glib可以,因为它是可移植的库)。
#include <fstream>
std::ifstream::pos_type filesize(const char* filename)
{
std::ifstream in(filename, std::ifstream::ate | std::ifstream::binary);
return in.tellg();
}
有关C ++中文件的更多信息,请参见http://www.cplusplus.com/doc/tutorial/files/。
编辑:这个答案是不正确的,因为tellg()不一定返回正确的值。看到http://stackoverflow.com/a/22986486/1835769
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句