Are there pitfalls for specific operating systems, I should know of?
There are many duplicates (1, 2, 3, 4, 5) of this question but they were answered decades ago. The v
(added in C++17) makes this very straightforward.
#include
#include
// ...
std::uintmax_t size = std::filesystem::file_size("c:\\foo\\bar.txt");
As noted in comments, if you're planning to use this function to decide how many bytes to read from the file, keep in mind that...
...unless the file is exclusively opened by you, its size can be changed between the time you ask for it and the time you try to read data from it.
– Nicol Bolas