我有一个VS2013 VC ++项目,我想创建一个std :: ifstream对象,如下所示:
#include "stdafx.h"
#include <fstream>
int _tmain(int argc, _TCHAR* argv[])
{
std::ifstream f;
return 0;
}
它按预期工作,但是如果我更改包含的标头顺序,编译器将发出错误:
#include <fstream>
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
std::ifstream f;
return 0;
}
error C2065: 'ifstream' : undeclared identifier
stdafx.h文件中的内容非常简单:
#pragma once
#include "targetver.h"
#include <stdio.h>
#include <tchar.h>
我的问题是,为什么标头包含的顺序会影响编译器查找std :: ifstream? stdafx.h包含的其他标头中是否定义了任何宏会影响结果?但是,当我在ifstream类上按F12并跳转到定义时,该类未显示为灰色,这意味着它们已启用并且编译器可以正确找到它们?我有一段时间的谷歌,但仍然不知道为什么编译失败。