如何用 C++ 获取文件的大小?
要获取 C++ 中的文件大小,首先打开文件并将其查找至结尾。tell() 将告诉我们流的当前位置,该位置是文件中的字节数。
示例
#include<iostream>
#include<fstream>
using namespace std;
int main() {
ifstream in_file("a.txt", ios::binary);
in_file.seekg(0, ios::end);
int file_size = in_file.tellg();
cout<<"Size of the file is"<<" "<< file_size<<" "<<"bytes";
}输出
Size of the file is 44 bytes
广告
数据结构
网络
关系数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP