我需要确定文件的字节大小。
编码语言是 C++,代码应该适用于 Linux、Windows 和任何其他操作系统。这意味着使用标准 C 或 C++ 函数/类。
这种微不足道的需求显然没有简单的解决方案。
使用 std 的流,您可以使用:
std::ifstream ifile(....);
ifile.seekg(0, std::ios_base::end);//seek to end
//now get current position as length of file
ifile.tellg();
如果您处理只写文件(std::ofstream),那么方法是另一种:
ofile.seekp(0, std::ios_base::end);
ofile.tellp();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)