我創建簡單的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文件(第二個代碼塊)中。 –