好的,所以我编写了一个涉及 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>
, 包含 ifstream
和 ofstream
类(当然还有 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/