[英]using header files and StdAfx.h
我有簡單的測試控制台應用程序。 我正在嘗試使用simple.h文件中定義的函數nike2,並且實現在simple.cpp中。 simple.h和simple.cpp文件都位於與主項目不同的目錄中。
我在項目瀏覽器中添加了simple.h到“Header files”和simple.cpp到“Source files”(我不確定是否需要)
控制台應用:
#include "stdafx.h"
#include "..\..\simple.h"
int _tmain(int argc, _TCHAR* argv[])
{
nike2(5);
return 0;
}
Simple.h
#include <cstdlib>
#include <iostream>
#ifndef MEMORY
#define MEMORY
int var;
int nike2(int f);
#endif /*MEMORY*/
Simple.cpp
#include <cstdlib>
#include <iostream>
#include "simple.h"
int nike2(int f)
{
return 0;
}
編譯時遇到錯誤:
Error 4 error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "StdAfx.h"' to your source? c:\c\simple.cpp 11 1 usingHeader
為什么? 什么是神奇的“StdAfx.h”用於?
UPD
simple.cpp現在看起來像這樣,但仍然有相同的錯誤
#include "C:\c\usingHeader\usingHeader\stdafx.h"
#include <cstdlib>
#include <iostream>
#include "simple.h"
int nike2(int f)
{
return 0;
}
Stdafx.h
用於制作預編譯的頭文件。 它包含一些最標准和最常用的include
s。
這主要是為了加快編譯過程,因為WinAPI是一件非常沉重的事情。
你也可以查看這個問題 ,它有一個更詳細的答案。
stdafx.h包含標題包含您不希望更改的內容。 標准庫之類的東西包含在stdafx.h中,所以它們只需要編譯一次。 您應該在任何需要的地方包含stdafx.h。 如果您不想使用它,可以在項目首選項中將其關閉。
什么是神奇的“StdAfx.h”用於?
它用於Visual Studio中的預編譯頭文件。
您可以將其包含在.cpp文件中,也可以為那些不需要包含所有Windows標頭的文件選擇“不使用預編譯標頭”。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.