Aug 19, 2013 at 9:18am UTC
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
Aug 19, 2013 at 9:29am UTC
Are you sure example.txt is in the same place as the program executable or your project directory? Try checking if (myfile.is_open())