C++-এ ফাইলের আকার বের করতে প্রথমে ফাইলটি ওপেন করুন এবং এন্ড (end) এ seek করুন। 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";
return 0;
}
আউটপুট
Size of the file is 44 bytes