Mega Code Archive

 
Categories / C++ Tutorial / File Stream
 

Open a file as binary file and get its size

#include <fstream> #include <iostream> using namespace std; int main ()  {   long start,end;   ifstream myfile ("test.txt", ios::in|ios::binary);      start = myfile.tellg();   myfile.seekg (0, ios::end);   end = myfile.tellg();   myfile.close();      cout << "size of " << "test.txt";   cout << " is " << (end-start) << " bytes.\n";   return 0; } size of test.txt is 25 bytes.