为什么VisualStudio2017给我一个模糊的变量错误而其他编译器没有?

时间:2018-04-12 16:38:00

标签: c++ visual-studio-2017

我正在使用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;
}

0 个答案:

没有答案