在查找预编译头时跳过

num*_*l25 12 c++ visual-studio-2008 visual-studio visual-c++

所以有些原因,我的.cpp文件缺少它的头文件.但我没有在其他地方包含头文件.我刚开始所以我检查了我制作的所有文件

enginuity.h

#ifndef _ENGINE_
#define _ENGINE_

class Enginuity
{

public:
    void InitWindow();

};
Run Code Online (Sandbox Code Playgroud)

enginuity.cpp

#include "Enginuity.h"


void Enginuity::InitWindow()
{

}
Run Code Online (Sandbox Code Playgroud)

main.cpp中

#include "stdafx.h"
#include "GameProject1.h"

#define MAX_LOADSTRING 100

// Global Variables:
HINSTANCE hInst;                                // current instance
TCHAR szTitle[MAX_LOADSTRING];                  // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING];            // the main window class name

// Forward declarations of functions included in this code module:
ATOM                MyRegisterClass(HINSTANCE hInstance);
BOOL                InitInstance(HINSTANCE, int);
LRESULT CALLBACK    WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK    About(HWND, UINT, WPARAM, LPARAM);

int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{

code.....
#endif
Run Code Online (Sandbox Code Playgroud)

不知道发生了什么事.我得到的错误是

1>c:\users\numerical25\desktop\intro todirectx\gameproject\gameproject1\gameproject1\enginuity.cpp(1) : warning C4627: '#include "Enginuity.h"': skipped when looking for precompiled header use
1>        Add directive to 'stdafx.h' or rebuild precompiled header
1>c:\users\numerical25\desktop\intro todirectx\gameproject\gameproject1\gameproject1\enginuity.cpp(8) : fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?
Run Code Online (Sandbox Code Playgroud)

Bil*_*eal 34

你读过错误信息了吗?

致命错误C1010:查找预编译头时意外结束文件.你忘了在你的来源添加'#include"stdafx.h"'吗?

我没有看到#include "stdafx.h"enginuity.cpp.;)如果您正在使用预编译头,则需要在每个源(.cpp)文件中包含预编译头.

  • 让我想念自己是一名助教."我收到的错误是'意外的结束;可能缺少分号',我该怎么办?" "嗯......你错过了一个分号吗?" "哦耶!" (15认同)
  • @num不,你可以(并且必须)在每个cpp文件中包含它.`#pragma once`或header guard做的唯一事情就是阻止你在同一个cpp文件中包含两次标题 (2认同)

Gor*_*las 21

当stdafx.h包含在位于stdafx.h所在的父文件夹中的cpp文件中时,我才遇到此错误.

#include "subfolder\stdafx.h"
Run Code Online (Sandbox Code Playgroud)

导致编译错误.将其更改为:

#include "stdafx.h"
Run Code Online (Sandbox Code Playgroud)

修复了编译错误,然后intellisense吓坏了.

该"修正"的智能感知,根据有人在微软这里,是添加"$(PROJECTDIR)"(或任何stdafx.h中是),以目录列表下的项目- >属性- >配置Propertes-> C/C++ - > General-> Additional Include Directories.

我已经在Visual Studio 2012中验证了这一点.也应该在2010年工作.


Joh*_*McG 6

你要么想要排队

#include "stdafx.h"
Run Code Online (Sandbox Code Playgroud)

在所有.cpp文件的顶部(在这种情况下,enenuity.cpp是唯一缺少它的人.

或禁用项目中的预编译头文件.

如果在项目中启用了预编译头,Visual C++将#include在所有源文件的顶部查找该指令.如果它不在那里,你会得到你收到的负面评论.


Vik*_*tor 5

如果批准的解决方案不适用于您:

在我的情况下,stdafx.h包含在我的.cpp文件中的其他包含之后.

在.cpp文件的顶部设置#include"stdafx.h"语句修复了我的错误.