文件的意外结束

Unexpected end of a file

本文关键字:结束 意外 文件      更新时间:2023-10-16

当尝试在VS2010 Ultimate sp1中#包括任何std头在"stdafx.h"我得到一个错误:
致命错误C1004:发现意外的文件结束符
有没有其他人遇到过这种情况,或者我的安装有问题?

编辑
我的main是这样的:

#include "stdafx.h"

int _tmain(int argc, _TCHAR* argv[])
{
    return 0;
}

stdafx.h看起来像这样:

#pragma once
#include "targetver.h"
#include <stdio.h>
#include <tchar.h>

// TODO: reference additional headers your program requires here
#include <_dbdao.h>//if I remove this line it will compile

stdafx.cpp如下所示:

#include "stdafx.h"

AND THERE IS MORE

Visual Studio编译器给出这个错误有几个原因。MSDN在这里解释

编译器到达源文件的末尾而没有解析构造。该代码可能缺少以下元素之一:

右括号
右括号
结束注释标记(*/)
分号

我猜它不是真的与stdafx.h文件有关,而是你有一个这样的类:

class A {
...
}

,不带}后面的分号。必须是

class A {
...
};

如果这不能解决问题,你应该按照第14条的建议去做。排除,直到它编译找到原因。

如果使用预编译头文件,则需要在项目中的每个源文件中包含stdafx.h。否则会导致您在这里引用的错误信息。