Cannot open include file ‘fstream.h' in Visual Studio 2010
There is a C++ project which is migrated from old VC++ 6.0, We use Visual Studio 2010 now.
We have the following small piece of C++ header code in a .h file:
#include "Accessor.h"
#include "SvMemDB.H"
#include "cnserver.h"
#include <fstream.h>
When we compile the project, we first got the following compile error:
error C1083: Cannot open include file: 'fstream.h': No such file or directory
The reason is in .NET 4.0, seems there is no more fstream.h, even all .h file is not recommanded.
please read the following explanation from StackOverflow:
**The difference between fstream and fstream.h
**fstream is somewhat more restrictive than the older fstream.h. One would possibly avoid problems by careful use of namespaces, but it would be a lot smarter to stick with one or the other.You should avoid using the *.h version as much as possible, because some implementations have bugs in their *.h version. Moreover, some of them support non-standard code that is not portable, and fail to support some of the standard code of the STL.
Furthermore, the *.h version puts everything in the global namespace. The extension-less version is more stable and it's more portable. It also places everything in the std namespace.
Conclusion
fstream.h is an old style method of including std C++ headers, and in opposite to fstream you don't have to declare that you're using the std namespace.It is sometimes recommended to use:
**#include <fstream>
using namespace std;**