问题及代码:
#include<iostream>
#include <fstream>
using namespace std;
const char * filename = "a.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-l) << " bytes.\n";
return 0;
}
运行结果:
学习总结:为什么输入五个字母显示的会是五个字节,难道不是7个字节么?求解答~~