意外的文件结束

时间:2011-08-01 19:07:01

标签: c++ visual-studio-2010

在VS2010 Ultimate sp1中尝试#include“stdafx.h”中的任何标题时,我收到错误:
致命错误C1004:发现意外的文件结尾
有没有其他人经历过这个或我的安装有什么问题?

编辑
我的主要看起来像这样:

#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"

并且没有更多

2 个答案:

答案 0 :(得分:1)

Visual Studio编译器出现此错误的原因有几个。 MSDN explains it here

  

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

     

闭合支架
  右括号
  结束评论标记(* /)
  分号

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

class A {
...
}

}之后没有分号。它必须是

class A {
...
};

如果这不能解决问题,你应该做tenfour建议的事情。消除,直到它编译找出导致它的原因。

答案 1 :(得分:0)

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

(此答案基于给定的信息)