This problem has been haunting me for weeks. I am using 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;
}
A simple program from C++ Primer. When I compile it, I get the following error information:
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 was trying to find some solution, and I got this:
which says:
SOLUTION FOUND:
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?
It should NOT be commented out. That part of stdlib.h should look like this:
It isn’t clear how it got to be commented in your version of the file. But it is clear that you don’t hesitate to edit compiler header files to get out of a problem. You may have done this before to bypass a problem and not remember it.
In general, this is a Really Really Bad Idea. Microsoft releases service packs and security updates that will update compiler header files. But it will not do so if the file was altered. Which may leave you with a nasty mixed bag of files that are no longer compatible with each other.
You will need to fix the damage done to these files. Pay attention to the modified timestamp of these files to find out which might have been changed. And copy those from a known-good machine of, say, a friend or colleague. Another possible approach (never tried it myself) is to move the altered files somewhere else and run setup again, asking for a repair. Not actually sure if that works, it should. Also re-apply service packs when you do it that way.