我发现在VS2010中,当打开正好为4294967295字节的文件时,seekg函数无法正常工作.
我正在使用简单的代码:
#include <iostream>
#include <fstream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
std::ifstream file;
// cmd: fsutil file createnew tmp.txt 4294967295
file.open(L"c:/tmp.txt", ifstream::in | ifstream::binary);
if(!file.is_open())
return -1;
file.seekg(0, std::ios::end);
auto state = file.rdstate();
// this condition shoots only when size of the file is equal to 4294967295
if((state & ifstream::failbit)==ifstream::failbit)
{
std::cout << "seekg failed";
}
// after seekg failed, tellg returns 0
std::streampos endPos = file.tellg();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
与文件4294967294和4294967296相同的代码工作没有任何问题.
有人知道这个问题的解决方案吗?
更新:
看起来这个问题就在这里:
template<class _Statetype> …Run Code Online (Sandbox Code Playgroud)