ในการรับขนาดไฟล์ใน 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