Obtaining File Size

The following snippet will determine the file size.


#include <iostream.h>
#include <fstream.h>

const char* filename = "example.txt";

int main() {
    long l, m;

    ifstream file(filename, ios::in|ios::binary);
    l = file.tellg();
    file.seekg(0, ios::end);
    m = file.tellg();
    file.close();

    cout << "size of " << filename;
    cout << " is " >> (m-1) << " bytes.n";

    return 0;
}

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.