Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using C++ filestreams (fstream), how can you determine the size of a file? [duplicate]

I'm sure I've just missed this in the manual, but how do you determine the size of a file (in bytes) using C++'s istream class from the fstream header?

like image 503
warren Avatar asked Mar 09 '10 14:03

warren


1 Answers

You can open the file using the ios::ate flag (and ios::binary flag), so the tellg() function will give you directly the file size:

ifstream file( "example.txt", ios::binary | ios::ate); return file.tellg(); 
like image 105
Pepus Avatar answered Sep 21 '22 11:09

Pepus