在VC的控制台程序中使用CString类、CFile类,需要添加头文件<afxwin.h>或者#include<afx.h>。
添加该文件时,如果也包含了<windows.h>,则要求<afxwin.h>在<windows.h>之前包含,否则会出错的。
如:fatal error C1189: #error : WINDOWS.H already included. MFC apps must not #include <windows.h>
有时候编译的时候回出现这样的错误:
fatal error C1189: #error : Building MFC application with /MD[d] (CRT dll version) requires MFC shared dll version. Please #define _AFXDLL or do not use /MD[d]
解决方案:右键项目->Configuration Properties -> C++ -> Code Generation ->选择 Runtime Library Multi-threaded Debug(/MTD)
如图: