我正在使用2个编译器,VisualStudio2017和MinGW发行版来关注cpluplus.com(c ++)教程。
MinGW发行版编译以下代码没有错误,但VisualStudio2017给出了一个关于变量“大小”的定义/初始化的模糊错误(第11行)。 为什么会这样?
// reading a complete binary file
#include <iostream>
#include <fstream>
using namespace std;
ifstream::pos_type size;
char * memblock;
int main () {
ifstream file ("example.bin", ios::in|ios::binary|ios::ate);
if (file.is_open()){
size = file.tellg();
memblock = new char [size];
file.seekg (0, ios::beg);
file.read (memblock, size);
file.close();
cout << "the complete file content is in memory";
delete[] memblock;
}else cout << "Unable to open file";
return 0;
}