To get a file’s size in C++ first open the file and seek it to the end. tell() will tell us the current position of the stream, which will be the number of bytes in the file.
Example
#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";
}Output
Size of the file is 44 bytes