2012年11月30日 星期五

vs++2012 can't open fstream.h 的解决方法

When VC6.0 project transfer to VC2012 , VC6.0的 #include <fstream.h>方式,
但是編譯時提示:
     fatal error C1083: 無法打開包括文件:“fstream.h”: No such file or directory

查閱了相關資料後,找到解決方法:

#include <fstream.h>
改成
#include <fstream> 
using namespace    std;   

為什麼會這樣子呢?這是因為:
The old iostream library was removed beginning in Visual C++ .NET 2003.
 reference :    http://msdn.microsoft.com/en-us/library/aa984818(v=vs.71).aspx

Differences in iostream Implementation


The old iostream library was removed beginning in Visual C++ .NET 2003.
The main difference between the Standard C++ Library and previous run-time libraries is in the iostream library. Details of the iostream implementation have changed, and it may be necessary to rewrite parts of your code that use iostream if you want to link with the Standard C++ Library.
You will have to remove any old iostream headers (fstream.h, iomanip.h, ios.h, iostream.h, istream.h, ostream.h, streamb.h, and strstrea.h) you have included in your code and add one or more of the new Standard C++ iostream headers (<fstream>, <iomanip>, <ios>, <iosfwd>, <iostream>, <istream>, <ostream>, <sstream>, <streambuf>, and <strstream>, all without the .h extension).
The following list describes behavior in the new Standard C++ iostream library that differs from behavior in the old iostream library.
In the new Standard C++ iostream library:
  • open functions do not take a third parameter (the protection parameter).
  • You cannot create streams from file handles.
  • With a couple of exceptions, all names in the new Standard C++ Library are in the std namespace. See Using C++ Library Headers for more information.
  • You cannot open ofstream objects with the ios::out flag alone. The ios::out flag must be combined with another ios enumerator in a logical OR; for example, with ios::inor ios::app.
  • ios::good no longer returns a nonzero value after reaching the end-of-file because the eofbit state is set.
  • ios::setf(_IFlags) should not be used with a flag value of ios::decios::oct, or ios::hex unless you know that none of the base flags are currently set. The formatted input/output functions and operators assume that only one base is set. Instead, use ios_base. For example, setfios_base::oct, ios_base::basefield ) clears all base information and sets the base to octal.
  • ios::unsetf returns void instead of the previous value.
  • istream::getchar& _Rch ) does not assign to Rch if there is an error.
  • istream::getchar* _Pchint _Ncountchar _Delim ) is different in three ways:
    • When nothing is read, failbit is set.
    • An eos is always stored after characters extracted (this happens regardless of the outcome).
    • A value of -1 for _Ncount is an error.
  • istream::seekg with an invalid parameter does not set failbit.
  • The return type streampos is a class with overloaded operators. In functions that return a streampos value (such as istream::tellgostream::tellpstrstreambuf::seekoff, and strstreambuf::seekpos), you should cast the return value to the type required: streamofffpos_t, or mbstate_t.
  • The first function parameter (_Falloc) in strstreambuf::strstreambuf( _Falloc, _Ffree ) takes a size_t argument, not a long.
In addition to the above changes, the following functions, constants, and enumerators that are elements of the old iostream library are not elements of the new iostream library:
  • attach member function of filebuffstream ifstream, and ofstream
  • fd member function of filebuffstream ifstream, and ofstream
  • filebuf::openprot
  • filebuf::setmode
  • ios::bitalloc
  • ios::nocreate
  • ios::noreplace
  • ios::sync_with_stdio
  • streambuf::out_waiting
  • streambuf::setbuf (use rdbuf -> pubsetbuf for the same behavior)



沒有留言:

張貼留言