在支持MFC的Win32控制台工程中一般有如下宏
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
定义了该宏会导致include fstream头文件失败,如下:
d:/Program Files/Microsoft Visual Studio .NET 2003/Vc7/include/fstream(465) : error C2061: syntax error : identifier '_DebugHeapTag'
d:/Program Files/Microsoft Visual Studio .NET 2003/Vc7/include/fstream(457) : while compiling class-template member function 'void std::basic_filebuf<_Elem,_Traits>::_Initcvt(std::basic_filebuf<_Elem,_Traits>::_Cvt *)'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
d:/Program Files/Microsoft Visual Studio .NET 2003/Vc7/include/fstream(484) : see reference to class template instantiation 'std::basic_filebuf<_Elem,_Traits>' being compiled
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
碰到类似问题,去掉上面的宏就可以解决了,或者把#include <fstream>放到宏的上面.