how to get length of a file in c++

#include <iostream>
#include <fstream>

int main() {
    std::ifstream file("example.txt", std::ios::binary | std::ios::ate);
    std::streampos fileSize = file.tellg();
    file.close();
    std::cout << "Size of the file is: " << fileSize << " bytes" << std::endl;

    return 0;
}