C++ 意外的文件结尾错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8862840/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unexpected end of file error
提问by Andrey Chernukha
I hope you can help me, cause I have no idea about what's going on. I'm having the following error while trying to add Beecrypt library to my project:
我希望你能帮助我,因为我不知道发生了什么。尝试将 Beecrypt 库添加到我的项目时出现以下错误:
fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?
致命错误 C1010:查找预编译头时文件意外结束。您是否忘记将“#include“stdafx.h””添加到您的源代码中?
Actually I did not forget to add #include "stdafx" to my source. The compiler points the error to be at the end of this .cxx file:
实际上我没有忘记在我的源代码中添加 #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;
}
and here is h file:
这是 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
Sorry for so much code.
抱歉,代码太多。
回答by Wacek
Goto SolutionExplorer (should be already visible, if not use menu: View->SolutionExplorer).
转到 SolutionExplorer(应该已经可见,如果没有使用菜单:View->SolutionExplorer)。
Find your .cxx file in the solution tree, right click on it and choose "Properties" from the popup menu. You will get window with your file's properties.
在解决方案树中找到您的 .cxx 文件,右键单击它并从弹出菜单中选择“属性”。您将获得包含文件属性的窗口。
Using tree on the left side go to the "C++/Precompiled Headers" section. On the right side of the window you'll get three properties. Set property named "Create/Use Precompiled Header" to the value of "Not Using Precompiled Headers".
使用左侧的树转到“C++/预编译头文件”部分。在窗口的右侧,您将获得三个属性。将名为“创建/使用预编译头”的属性设置为“不使用预编译头”的值。
回答by Maheswar Reddy
If you do not use precompiled headers in your project, set the Create/Use Precompiled Header property of source files to Not Using Precompiled Headers. To set this compiler option, follow these steps:
如果在项目中不使用预编译头,请将源文件的创建/使用预编译头属性设置为不使用预编译头。要设置此编译器选项,请执行以下步骤:
- In the Solution Explorer pane of the project, right-click the project name, and then click
Properties
. - In the left pane, click the
C/C++
folder. - Click the
Precompiled Headers
node. - In the right pane, click
Create/Use Precompiled Header
, and then clickNot Using Precompiled Headers
.
- 在项目的解决方案资源管理器窗格中,右键单击项目名称,然后单击
Properties
。 - 在左窗格中,单击
C/C++
文件夹。 - 单击
Precompiled Headers
节点。 - 在右窗格中,单击
Create/Use Precompiled Header
,然后单击Not Using Precompiled Headers
。
回答by Nawaz
You did forget to include stdafx.h
in your source (as I cannot see it your code). If you didn't, then make sure #include "stdafx.h"
is the firstline in your .cpp
file, otherwise you will see the same error even if you've included "stdafx.h"
in your source file (but not in the very beginningof the file).
您确实忘记包含stdafx.h
在您的源代码中(因为我看不到您的代码)。如果没有,请确保#include "stdafx.h"
是文件中的第一行.cpp
,否则即使您已包含"stdafx.h"
在源文件中(但不在文件的最开头),您也会看到相同的错误。
回答by jnnnnn
I also got this error, but for a .h
file. The fix was to go into the file Properties
(via Solution Explorer's file popup menu) and set the file type correctly. It was set to C/C++ Compiler
instead of the correct C/C++ header
.
我也遇到了这个错误,但对于一个.h
文件。修复方法是进入文件Properties
(通过解决方案资源管理器的文件弹出菜单)并正确设置文件类型。它被设置为C/C++ Compiler
而不是正确的C/C++ header
.
回答by Cody Gray
The line #include "stdafx.h"
mustbe the first line at the top of each source file, before any other header files are included.
在包含任何其他头文件之前,该行#include "stdafx.h"
必须是每个源文件顶部的第一行。
If what you've shown is the entire .cxx
file, then you didforget to include stdafx.h
in that file.
如果您显示的是整个.cxx
文件,那么您确实忘记包含stdafx.h
在该文件中。
回答by MiddleKay
I encountered that error when I forgot to uncheck the Precompiled header from the additional options in the wizard after naming a new Win32 console application.
当我在命名新的 Win32 控制台应用程序后忘记从向导中的附加选项中取消选中预编译头时遇到了该错误。
Because I don't need stdafx.h library, I removed it by going to Projectmenu, then click Propertiesor [name of our project] Propertiesor simply press Alt + F7. On the dropdownlist beside configuration, select All Configurations. Below that, is a tree node, click Configuration Properties, then C/C++. On the right pane, select Create/Use Precompiled Header, and choose Not using Precompiled Header.
因为我不需要 stdafx.h 库,所以我通过转到“项目”菜单将其删除,然后单击“属性”或[我们项目的名称] 属性或简单地按Alt + F7。在配置旁边的下拉列表中,选择All Configurations。在其下方是一个树节点,单击Configuration Properties,然后单击C/C++。在右侧窗格中,选择Create/Use Precompiled Header,然后选择Not using Precompiled Header。
回答by JordanBean
Change the Platform of your C++ project to "x64" (or whichever platform you are targeting) instead of "Win32". This can be found in Visual Studio under Build -> Configuration Manager. Find your project in the list and change the Platform column. Don't forget to do this for all solution configurations.
将您的 C++ 项目的平台更改为“x64”(或您所针对的任何平台)而不是“Win32”。这可以在 Visual Studio 中的 Build -> Configuration Manager 下找到。在列表中找到您的项目并更改平台列。不要忘记对所有解决方案配置执行此操作。