How to get filesize in C++ using C++17's std::filesystem

Recent versions of C++ have a built-in cross-platform filesystem library which supports many useful operations such as getting the filesize.

#include <filesystem>

// Usage example:
std::filesystem::file_size("myfile.bin");

Full example:

#include <filesystem>
#include <iostream>

int main() {
    std::uintmax_t filesize = std::filesystem::file_size("myfile.bin");
    std::cout << "Filesize in bytes is " << filesize << std::endl;
    return 0;
}