我创建简单的Win32控制台应用程序:预编译头和__AFXWIN_H__
#include "stdafx.h"
#include <iostream>
#include "conio.h"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
cout << "Hello World" << endl;
int num;
cin >> num;
return 0;
}
它编译罚款。
然后我试图添加库。我有DLL和.h文件。
我已经包括my.h文件:
#include "stdafx.h"
#include "my.h"
#include <iostream>
#include "conio.h"
"my.h"
包含线路:
#ifndef __AFXWIN_H__
#error include 'stdafx.h' before including this file for PCH
#endif
编译后,我得到了错误:
include 'stdafx.h' before including this file for PCH
可是我已经列入“stdafx 。H'。我已经测试了使用/不使用预编译头文件的两个选项 - 相同的结果。哪里有问题?
stdafx.h必须包含在.cpp文件中而不是.h文件中。 –
它包含在我的应用程序cpp文件(第一个代码块) – vico
它包含在你的h文件(第二个代码块)中。 –