Sophie Sperner Sophie Sperner - 1 year ago 112
C++ Question

How can I get a file's size in C++?

Let's create a complementary question to this one.
What is the most common way to get the file size in C++?
Before answering, make sure it is portable (may be executed on Unix, Mac and Windows),
reliable, easy to understand and without library dependencies (no boost or qt, but for instance glib is ok since it is portable library).

Answer Source
#include <fstream>

std::ifstream::pos_type filesize(const char* filename)
    std::ifstream in(filename, std::ifstream::ate | std::ifstream::binary);
    return in.tellg(); 

See for more information on files in C++.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download