file i/o

i m having error in my output.. in c++ documentation i took one program and then compiled it, then i m getting wrong output .. could someone help me ??


// obtaining file size
#include <iostream>
#include <fstream>
using namespace std;

int main () {
long begin,end;
ifstream myfile ("example.txt");
begin = myfile.tellg();
myfile.seekg (0, ios::end);
end = myfile.tellg();
myfile.close();
cout << "size is: " << (end-begin) << " bytes.\n";
return 0;
}
size is: 40 bytes.

but i am getting output as "size is : 0 bytes
Are you sure example.txt is in the same place as the program executable or your project directory? Try checking if(myfile.is_open())
Topic archived. No new replies allowed.