I'm trying to read a large binary file but my code fails to open files larger than 4GB. Here's my code (I'm using Visual Studio 2012, compiling in x64):
#include "stdafx.h"
#include <fstream>
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
char* filename = "testfile";
ifstream file (filename, ios::in|ios::binary|ios::ate);
if (file.is_open())
{
cout << "file is open" << endl;
}
else
{
cout << "couldn't open file" << endl;
}
return 0;
}
As suggested in the comments I checked the output of GetLastError()
with the following modification:
// ...
ifstream file (filename, ios::in|ios::binary|ios::ate);
DWORD lastError = GetLastError();
cout << lastError << endl; // -> 87
// ...
Do you have any advice?