unexpected end of file while looking for precompiled header directive  经常遇到这种情况,我发现只要在每个cpp文件开头都加上#include "stdafx.h",就行了。但有时候对一些作为库使用的cpp文件最好还是不要加这些东西,请问还有什么其他的解决办法么?最好也能仔细讲一下其中的原理,谢谢了先。

解决方案 »

  1.   

    去掉预编译头。在project -> setting -> c++ -> category,选择precompliled headers ,然后选择
    not using procompliled headers
      

  2.   

    那就把cpp文件中的代码转移到h文件中
      

  3.   

    #include "stdafx.h"
    或如一楼所说不用 procompliled headers
      

  4.   

    但推荐#include "stdafx.h",因为用预编译头可以显著减少编译时间。
      

  5.   

    一楼的,你说去掉预编译头,那不是整个项目都去掉了么?我是想有些和微软相关的还用这些precompliled headers ,而有些单独的库最好不要打上这些微软的烙印。
      

  6.   

    在project -> setting -> c++ -> category,选择precompliled headers ,然后选择
    not using procompliled headers,比较好
    加#include "stdafx.h"有时没有用
      

  7.   

    另外faq里有这个问题的答案,你可以查一下
      

  8.   

    我试了下写#include "stdafx.h"发现了另一个问题!
    我的代码是:
    #include <afxwin.h>
    #include "Hello.h"CMyApp myApp;
    ...
    如果写成
    #include "stdafx.h"
    #include <afxwin.h>
    #include "Hello.h"CMyApp myApp;
    ...
    编译没有任何错误,如果写成这样:
    #include <afxwin.h>
    #include "Hello.h"
    #include "stdafx.h"CMyApp myApp;
    ...
    就有三个错:
    1.error C2146: syntax error : missing ';' before identifier 'myApp';
    2.error C2501: 'CMyApp' : missing storage-class or type specifiers;
    3.fatal error C1004: unexpected end of file found;
    这又是怎么一回事呢?
    我初学MFC,还请多多指教!
      

  9.   

    #include "stdafx.h" 一定要写在第一行,赫赫。
      

  10.   

    ??没有原因吗?算了不问了,我才看到第一章第二小节,Hello这个程序还没看完呢,自己琢磨琢磨再说吧,谢啦!