简体   繁体   中英

Are ifstream and ofstream non-standard c++ headers?

Ok, so I was coding a C++ console app involving File - IO. In c++, to apply file io, you have the import one of three headers, them being <ifstream> , <ofstream> , and <fstream> . In Visual Studio Community 2015, at first when I wrote this code:

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

The first thing I noticed right away, is that the Intellisense gave me an error stating that it had an error opening ifstream, as it "was not found". After posting on a different forum, I got the solution to use the <fstream> header, since it has the classes for ifstream and ofstream, and then my code worked. But I only need the ifstream class, so I think it is unnecessary that I have to bring fstream in as well. This leads me to my question, are ifstream and ofstream non-standard headers for Windows Visual Studio, and is there any way I can include them?

Yes, the only standard header is <fstream> , containing both ifstream and ofstream classes (and fstream of course).

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

In the table, there is no <ifstream> or <ofstream> .

The headers are nonstandard for windows. You can't include them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM