Problem with #include <ifstream>

I have the following lines in my program:

1
2
3
#include <fstream>
#include <ifstream>
#include <ofstream> 


After ‘building’, Visual Studio says about line 2: "Cannot open source file ifstream", and "Cannot open include file: 'ifstream': No such file or directory"

There are similar messages about line 3.

Please can someone tell what is wrong with these two lines?
Those lines are fine. Something's wrong with the configuration of your project. Are you perchance building your project as a C project by mistake?

-Albatross


EDIT: Got my wires crossed. See below.
Last edited on
Both ifstream and ofstream are defined in the fstream header you shouldn't need anything other than #include <fstream>
Avoiding assumptions ... you don't happen to be on a very, very old version of VS do you?
The header files ifstream and ofstream are not in the C++ standard.
As jlb said, it's just <fstream> which contains all the classes.

https://en.cppreference.com/w/cpp/header

___________________________________________

Edit: It's worth asking, where did you find the code? On a random comment in an MSDN forum post? Or an actual codebase?

It seems there did used to be pre-standard headers in compilers a long time ago, like g++, where <ifstream.h> was a thing, but I can't find anything specifically about <ifstream>. So jonnin might also be correct, you might be looking at source code used with a gosh darn old compiler.
Last edited on
Many thanks for these points.

I have found references to ifstream and ofstream in at least one book and examples on the web.

I'm using the 'community' version of Visual Studio which has been downloaded and installed quite recently but compared with other versions may be "very very old".
Just to be clear: There's nothing wrong with your compiler/Visual Studio, it's working as intended.
It's the book or web examples that are wrong.
Last edited on
compared with other versions may be "very very old".
I was talking about pre year 2000, back before the no .h header file syntax.
the community edition is just fine.

post a small example of what you are doing that isnt working and let us see if we can spot the issues if you still need help.
Last edited on
Topic archived. No new replies allowed.