当前位置: 动力学知识库 > 问答 > 编程问答 >

c++ - error C2065: 'errno' : undeclared identifier in <string> in Visual Studio 2012

问题描述:

I had a project running in Visual Studio 2010. Now I am using Visual Studio 2012.

Now I am getting below error while building the project.

I have looked into Google and SO as well. 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.

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; to get the error message you cite, the macro must be undefined. <string> includes (indirectly) a file which defines it. 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 #undefed it. To verify this, put your #include <string> as the very first include of your source, and see if this solves the problem. If it does, then you have to find the file which does the #undef, and fix it.

网友答案:

I had the same issue. Strangely enough, the problem was not including "using namespace std;" under the header file includes. Apparently, program would recognize "string" unless I did this, even though "char", "float", etc were recognized.

分享给朋友:
您可能感兴趣的文章:
随机阅读: