Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/139.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 意外的文件结束错误_C++_Visual Studio 2008_Visual C++_Compiler Errors_Precompiled Headers - Fatal编程技术网

C++ 意外的文件结束错误

C++ 意外的文件结束错误,c++,visual-studio-2008,visual-c++,compiler-errors,precompiled-headers,C++,Visual Studio 2008,Visual C++,Compiler Errors,Precompiled Headers,我希望你能帮助我,因为我不知道发生了什么事。尝试将Beecrypt库添加到项目时出现以下错误: 致命错误C1010:查找预编译头时出现意外的文件结尾。您是否忘记在源代码中添加“#include”stdafx.h” 事实上,我没有忘记在我的源代码中添加#include“stdafx”。编译器将错误指向此.cxx文件的末尾: #define BEECRYPT_CXX_DLL_EXPORT #ifdef HAVE_CONFIG_H # include "config.h" #endif #incl

我希望你能帮助我,因为我不知道发生了什么事。尝试将Beecrypt库添加到项目时出现以下错误:

致命错误C1010:查找预编译头时出现意外的文件结尾。您是否忘记在源代码中添加“#include”stdafx.h”

事实上,我没有忘记在我的源代码中添加#include“stdafx”。编译器将错误指向此.cxx文件的末尾:

#define BEECRYPT_CXX_DLL_EXPORT

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include "beecrypt/c++/security/SecureRandom.h"
#include "beecrypt/c++/security/SecureRandomSpi.h"
#include "beecrypt/c++/security/Security.h"

using namespace beecrypt::security;

SecureRandom* SecureRandom::getInstance(const String& algorithm) throw       (NoSuchAlgorithmException)
 {
Security::spi* tmp = Security::getSpi(algorithm, "SecureRandom");

assert(dynamic_cast<SecureRandomSpi*>(tmp->cspi));

SecureRandom* result = new SecureRandom(reinterpret_cast<SecureRandomSpi*>(tmp->cspi), tmp->prov, tmp->name);

delete tmp;

return result;
}

 SecureRandom* SecureRandom::getInstance(const String& type, const String& provider) throw (NoSuchAlgorithmException, NoSuchProviderException)
  {
Security::spi* tmp = Security::getSpi(type, "SecureRandom", provider);

assert(dynamic_cast<SecureRandomSpi*>(tmp->cspi));

SecureRandom* result = new SecureRandom(reinterpret_cast<SecureRandomSpi*>(tmp->cspi), tmp->prov, tmp->name);

delete tmp;

return result;
    }

   SecureRandom* SecureRandom::getInstance(const String& type, const Provider& provider) throw (NoSuchAlgorithmException)
   {
Security::spi* tmp = Security::getSpi(type, "SecureRandom", provider);

assert(dynamic_cast<SecureRandomSpi*>(tmp->cspi));

SecureRandom* result = new SecureRandom(reinterpret_cast<SecureRandomSpi*>(tmp->cspi), tmp->prov, tmp->name);

delete tmp;

return result;
     }

  void SecureRandom::getSeed(byte* data, int size)
 {
entropyGatherNext(data, size);
 }

 SecureRandom::SecureRandom()
 {
Security::spi* tmp = Security::getFirstSpi("SecureRandom");

assert(dynamic_cast<SecureRandomSpi*>((SecureRandomSpi*) tmp->cspi));

_rspi = (SecureRandomSpi*) tmp->cspi;
_type = tmp->name;
_prov = tmp->prov;

delete tmp;
   }

  SecureRandom::SecureRandom(SecureRandomSpi* rspi, const Provider* provider, const String& type)
  {
_rspi = rspi;
_prov = provider;
_type = type;
  }

 SecureRandom::~SecureRandom()
 {
delete _rspi;
 }

void SecureRandom::generateSeed(byte* data, int size)
 {
_rspi->engineGenerateSeed(data, size);
 }

 void SecureRandom::setSeed(const byte* data, int size)
 {
_rspi->engineSetSeed(data, size);
 }

  void SecureRandom::nextBytes(byte* data, int size)
 {
_rspi->engineNextBytes(data, size);
 }

 const String& SecureRandom::getType() const throw ()
 {
return _type;
 }

  const Provider& SecureRandom::getProvider() const throw ()
 {
return *_prov;
  }

很抱歉有这么多代码。

您确实忘了在源代码中包含
stdafx.h
(因为我看不到您的代码)。如果没有,请确保
#include“stdafx.h”
.cpp
文件中的第一行,否则即使在源文件(但不是文件的最开始)中包含
“stdafx.h”
,您也会看到相同的错误。

#include“stdafx.h”
必须是每个源文件顶部的第一行,然后才包括任何其他头文件

如果您显示的是整个
.cxx
文件,那么您确实忘记了在该文件中包含
stdafx.h

转到SolutionExplorer(如果不使用菜单:View->SolutionExplorer,则应该已经可见)

在解决方案树中找到您的.cxx文件,右键单击它并从弹出菜单中选择“属性”。您将获得包含文件属性的窗口


使用左侧的树转到“C++/预编译头”部分。在窗口的右侧,您将看到三个属性。将名为“创建/使用预编译头”的属性设置为“不使用预编译头”的值。

在命名新的Win32 console应用程序后,当我忘记从向导中的其他选项中取消选中预编译头时,遇到了该错误


因为我不需要stdafx.h库,所以我通过转到项目菜单将其删除,然后单击属性[项目名称]属性或只需按Alt+F7。在配置旁边的下拉列表中,选择所有配置。下面是一个树节点,单击配置属性,然后单击C/C++。在右侧窗格中,选择创建/使用预编译头,然后选择不使用预编译头,我也收到了这个错误,但是对于
.h
文件。修复方法是进入文件
属性
(通过解决方案资源管理器的文件弹出菜单)并正确设置文件类型。它被设置为<代码> C/C++编译器< /> >而不是正确的<代码> C/C++头> <代码> .p/> 将C++项目的平台改为“x64”(或者无论你在哪个平台上),而不是“Win32”。这可以在Visual Studio中的“生成->配置管理器”下找到。在列表中找到您的项目并更改平台列。不要忘记对所有解决方案配置执行此操作。

如果在项目中不使用预编译头,请将源文件的“创建/使用预编译头”属性设置为“不使用预编译头”。要设置此编译器选项,请执行以下步骤:

  • 在项目的“解决方案资源管理器”窗格中,右键单击项目名称,然后单击
    Properties
  • 在左侧窗格中,单击
    C/C++
    文件夹
  • 单击
    预编译标题
    节点
  • 在右侧窗格中,单击
    创建/使用预编译头
    ,然后单击
    不使用预编译头

您是否试图将Beecrypt库作为一个单独的
项目添加到您的
解决方案中
?可能是,我不知道您的确切意思。但如果您有成功将Beecrypt添加到解决方案中的经验,那么我非常需要您的建议。如果你说俄语(我想是你的名字)——也许用俄语会更方便?我没有这种经验,我也不再用VS了。但我记得有一种设置可以将这个预编译头功能用于一个单独的项目。我不明白是什么,当我写第一行时,我就无法包含“beecrypt/c++/security/SecureRandom.h”。它告诉我没有这样的文件或文件directory@AndreyChernukha不过,这是一个单独的问题,不能通过省略
#include
来解决!编译器在找到此头之前不会对代码执行任何操作。它没有去寻找你的头球。如果您不想在main.cpp文件中包含
,则需要关闭预编译头。我怎么能在main.cpp文件中打开该文件(“beecrypt/c++/security/SecureRandom.h”),而不是在SecureRandom.cxx中打开它呢?我遵循了,并将“清除预编译头复选框”误读为“选中预编译头复选框”!我以为这是整个项目的一个设置,但没有意识到单个文件可以有不同的预编译头选项。这成功了,谢谢!但是有人知道为什么会发生错误,以及为什么在实际包含stdafx.h时会出现此错误吗?这也为我解决了这个问题,因为我有一个.cpp使用了预编译头,而另一个.c没有。每个文件都可以有自己的预编译头的提示很好。然而,在我看来,这只是一个解决办法。我有同样的问题,你的解决方案解决了它!,我认为当你创建一个.cpp文件,然后将其重命名为一个头文件时,就会发生这种情况。谢谢你们,伙计们!当您错误地创建了一个.cpp文件,然后将其重命名为.h文件时,确实存在这个问题。它可以工作,为什么可以工作?其他合理的解决方案并没有奏效,但这一个成功了,而且还没有明显的原因或解释。
#ifndef _CLASS_BEE_SECURITY_SECURERANDOM_H
#define _CLASS_BEE_SECURITY_SECURERANDOM_H

#include "beecrypt/beecrypt.h"

#ifdef __cplusplus

#include "beecrypt/c++/security/SecureRandomSpi.h"
using beecrypt::security::SecureRandomSpi;
#include "beecrypt/c++/security/Provider.h"
using beecrypt::security::Provider;
#include "beecrypt/c++/security/NoSuchAlgorithmException.h"
using beecrypt::security::NoSuchAlgorithmException;
#include "beecrypt/c++/security/NoSuchProviderException.h"
using beecrypt::security::NoSuchProviderException;

 namespace beecrypt {
namespace security {
    /*!\ingroup CXX_SECURITY_m
     */
    class BEECRYPTCXXAPI SecureRandom : public Object
    {
    public:
        static SecureRandom* getInstance(const String& type)    throw (NoSuchAlgorithmException);
        static SecureRandom* getInstance(const String& type,    const String& provider) throw (NoSuchAlgorithmException, NoSuchProviderException);
        static SecureRandom* getInstance(const String& type,   const Provider& provider) throw (NoSuchAlgorithmException);

        static void getSeed(byte*, int);

    private:
        SecureRandomSpi* _rspi;
        const Provider*  _prov;
        String           _type;

    protected:
        SecureRandom(SecureRandomSpi* spi, const Provider*   provider, const String& type);

    public:
        SecureRandom();
        virtual ~SecureRandom();

        void generateSeed(byte*, int);
        void nextBytes(byte*, int);
        void setSeed(const byte*, int);

        const String& getType() const throw ();
        const Provider& getProvider() const throw ();
    };
}
   }

   #endif

   #endif