至少对于在64位CentOS 5上使用G ++ 4.1和4.4的用户而言,以下代码可以按预期工作,即,程序输出的长度与stat()调用返回的长度相同。
#include <iostream>#include <fstream>using namespace std;int main () { int length; ifstream is; is.open ("test.txt", ios::binary | std::ios::in); // get length of file: is.seekg (0, ios::end); length = is.tellg(); is.seekg (0, ios::beg); cout << "Length: " << length << "nThe following should be zero: " << is.tellg() << "n"; return 0;}


