c++ - ifstream 和 ofstream 是非标准 C++ header 吗?

标签 c++ visual-c++ ifstream ofstream

好的,所以我编写了一个涉及 File - IO 的 C++ 控制台应用程序。在 C++ 中,要应用文件 io,您需要导入三个 header 之一,它们是 <ifstream> , <ofstream> , 和 <fstream> .在 Visual Studio Community 2015 中,起初我写这段代码时:

#include <ifstream>
int main()
{
    std::ifstream inf("testingifstream.txt");
}

我立即注意到的第一件事是,Intellisense 给了我一个错误,指出打开 ifstream 时出错,因为它“未找到”。在不同的论坛上发帖后,我得到了使用 <fstream> 的解决方案 header ,因为它有 ifstream 和 ofstream 的类,然后我的代码就可以工作了。但是我只需要ifstream类,所以我觉得没必要把fstream也带进来。这引出了我的问题,ifstream 和 ofstream 是 Windows Visual Studio 的非标准 header ,有什么方法可以包含它们吗?

最佳答案

是的,唯一的标准标题是<fstream> , 包含 ifstreamofstream类(当然还有 fstream)。

[17.6.1.2] The C++ standard library provides 55 C++ library headers, as shown in Table 14.

表中没有<ifstream><ofstream> .

关于c++ - ifstream 和 ofstream 是非标准 C++ header 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38210174/

相关文章:

c++ - 为什么我无法输入文件中的整数?

c++ - 数组中的最大 X 值

c++ - 包含头文件的顺序是什么?

C++从字节数组实时播放音频

c++ - 为什么下面的代码在 MSVC 中不能编译,但在 g++ 中可以编译?

c++ - 使用 Visual C++ 进行地址 sanitizer : ignore read buffer overflows while still catching write buffer overflows

c++ - C++ 命名空间的奇怪行为

c++ - 作为引用传递时 istream 的无效初始化错误

c++ - 按位读取文件 C++

c++ - 在集合中查找最近的元素