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


let's create complementary question this one. common way file size in c++? before answering, make sure portable (may executed on unix, mac , windows), reliable, easy understand , without library dependencies (no boost or qt, instance glib ok since portable library).

#include <fstream>  std::ifstream::pos_type filesize(const char* filename) {     std::ifstream in(filename, std::ifstream::ate | std::ifstream::binary);     return in.tellg();  } 

see http://www.cplusplus.com/doc/tutorial/files/ more information on files in c++.


Comments