这个问题已经困扰我好几个星期了。我正在使用 MS vs2010。
#include <iostream>
int main()
{
std::cout << "Enter two numbers:" << std::endl;
int v1 = 0, v2 = 0;
std::cin >> v1 >> v2;
std::cout << "The sum of " << v1 << " and " << v2
<< " is " << v1 + v2 << std::endl;
return 0;
}
来自 C++ Primer 的一个简单程序。当我编译它时,我得到以下错误信息:
1>e:\program files\microsoft visual studio 10.0\vc\include\cstdlib(24): error C2039: 'exit' : is not a member of '`global namespace''
1>e:\program files\microsoft visual studio 10.0\vc\include\cstdlib(24): error C2873: 'exit' : symbol cannot be used in a using-declaration
我试图找到一些解决方案,我得到了这个:
其中说:
找到的解决方案:
I have researched this issue on the web and it seems like it is something that has been an issue for a lot of people. The solution to this is as simple as removing a comment.
I looked through the stdlib.h file, and found the the following line was commended out:
_CRTIMP __declspec(noreturn) void __cdecl exit(__in int _Code);
I took out the comment and recompiled it, and now it works.
I believe in some builds the stdlib.h file will automatically be compiled with that portion of the code commented out. simple uncomment and your code will work.
Apparently some people fixed the problem with this solution. However, I could not even find _CRTIMP __declspec(noreturn) void __cdecl exit(__in int _Code);
in my stdlib.h.
Anyone knows how to fix this?