c++ - 为什么编译器找不到类 std::ifstream?
问题描述
我有一个 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 并跳转到定义时,该类没有变灰,这意味着它们已启用并且编译器可以找到它们对吗?我有一段时间谷歌,但仍然无法弄清楚为什么它编译失败。
解决方案
推荐阅读
- java - 我的变量 loginSuccesful 自动更改
- php - PHP:对象实例上的 new 运算符创建一个对象实例。为什么?
- javascript - 防止函数在 java 脚本中函数的最后一条语句中调用自身
- angular - 更新到 v8 后,我的代码中的 ng 构建失败并出现“未找到导出”错误
- jquery - 单击按钮图标行为奇怪
- excel - 如何在 VBA 中有效地使用具有多个条件的 If 语句,将用户输入与范围进行比较?
- python - 如何从特殊点切割字符串
- python - 使用 Keras 层 Lambda 时如何修复“NoneType”对象没有属性“_inbound_nodes”
- html - Angular如何使用(更改)检测器通过按钮发布数据?
- blockstack - Blockstack-Radiks:缺少签名密钥