Data size example of c++ file
July 31st, 2010
No comments
The following example uses the member functions we have just seen to obtain the size of a file:
// obtaining file size
#include
#include
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;
}
output:
size is: 40 bytes.
Categories: Uncategorized