简体   繁体   English

错误C2065:“ errno”:中的未声明标识符 <string> 在Visual Studio 2012中

[英]error C2065: 'errno' : undeclared identifier in <string> in Visual Studio 2012

I had a project running in Visual Studio 2010 . 我有一个在Visual Studio 2010运行的项目。 Now I am using Visual Studio 2012 . 现在,我正在使用Visual Studio 2012 Now I am getting below error while building the project. 现在我在构建项目时遇到错误。 I have looked into Google and SO as well. 我也研究了GoogleSO But no where I got any solution. 但是我没有办法解决。

    c:\program files\microsoft visual studio 11.0\vc\include\string(557): error C2065: 'errno' : undeclared identifier
2>c:\program files\microsoft visual studio 11.0\vc\include\string(557): error C2065: 'errno' : undeclared identifier
2>c:\program files\microsoft visual studio 11.0\vc\include\string(562): error C2065: 'errno' : undeclared identifier
2>c:\program files\microsoft visual studio 11.0\vc\include\string(574): error C2065: 'errno' : undeclared identifier
2>c:\program files\microsoft visual studio 11.0\vc\include\string(579): error C2065: 'errno' : undeclared identifier

I have tried with including stdlib.h into the sting header file but still I am getting this same error. 我尝试将stdlib.h包含在sting头文件中,但是仍然遇到相同的错误。

Any help appreciated. 任何帮助表示赞赏。

There could be several possible reasons for this problem. 此问题可能有几种可能的原因。 The first thing you should do is to create a one line source: 您应该做的第一件事是创建一个行源:

#include <string>

and nothing else, and try to compile it. 没有别的,然后尝试对其进行编译。 If this doesn't compile, there is a problem with your installation, and you should reinstall it. 如果无法编译,则说明安装存在问题,应重新安装。 Then, just to be sure, delete everything in your source tree except the actual sources, project files and solution, and rebuild. 然后,请确保删除源树中除实际源,项目文件和解决方案之外的所有内容 ,然后重新构建。 There may be some old files laying around which are somehow causing the problem. 可能存在一些旧文件,这些旧文件以某种方式导致了问题。 I doubt it, but this is something you should do anyway, any time you upgrade a compiler, or even just install a patch. 我对此表示怀疑,但是无论如何,无论何时升级编译器,甚至只是安装补丁,都应该这样做。 (If you've got everything under source code control, which you should, the simplest solution is just to delete everything, and do a new, clean checkout.) (如果您应将所有内容置于源代码的控制之下,那么最简单的解决方案就是删除所有内容,然后进行新的干净签出。)

If these measures don't solve the problem (and somehow, I suspect they won't), there's a problem in your code base somewhere. 如果这些措施不能解决问题(某种程度上,我怀疑它们不会解决),则您的代码库中存在问题。 errno is required to be a macro by the standard; 标准要求errno为宏; to get the error message you cite, the macro must be undefined. 若要获取您引用的错误消息,该宏必须未定义。 <string> includes (indirectly) a file which defines it. <string>包含(间接)定义它的文件。 Given this, the only cause I can think of is that an earlier include file has already included a file which defines errno , and then #undef ed it. 鉴于此,我唯一想到的原因是,一个较早的包含文件已经包含了一个定义errno的文件,然后#undef ed它。 To verify this, put your #include <string> as the very first include of your source, and see if this solves the problem. 为了验证这一点,请将您的#include <string>作为源的第一个include,然后看能否解决问题。 If it does, then you have to find the file which does the #undef , and fix it. 如果是这样,那么您必须找到执行#undef的文件并进行修复。

I had the same issue. 我遇到过同样的问题。 Strangely enough, the problem was not including "using namespace std;" 奇怪的是,问题不包括“使用命名空间std”。 under the header file includes. 头文件下的include。 Apparently, program would recognize "string" unless I did this, even though "char", "float", etc were recognized. 显然,除非我识别了“ char”,“ float”等,否则程序将识别“ string”,除非我这样做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM