当在vs2010中使用iostream时,我得到错误C2039:'exit':不是'`全局命名空间''的成员 [英] When using iostream in vs2010, I get error C2039: 'exit' : is not a member of '`global namespace''

查看:199
本文介绍了当在vs2010中使用iostream时,我得到错误C2039:'exit':不是'`全局命名空间''的成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题困扰了我几个星期。我使用MS vs2010。

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;
}

一个来自C ++ Primer的简单程序。当我编译它,我得到以下错误信息:

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):错误C2039:'exit':不是'`全局命名空间'的成员

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:\程序文件\microsoft visual studio 10.0 \vc\include\cstdlib(24):错误C2873:'exit':符号不能用于使用声明

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:

http://social.msdn.microsoft.com/Forums/nl-NL/Vsexpressvc / thread / 31385f37-94b8-4297-b054-7fdbc5b1f51e

其中说:


解决方法:

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.

我查看了stdlib.h文件,发现以下行被推荐:

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.

我相信在某些构建中,stdlib.h文件将自动编译为代码注释掉的那部分。简单的注释和你的代码将工作。

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.

显然有些人解决这个问题的解决方案。但是,我甚至不能在我的stdlib.h中找到 _CRTIMP __declspec(noreturn)void __cdecl exit(__在int _Code);

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?

推荐答案


我浏览stdlib.h文件,发现以下行被推荐:

I looked through the stdlib.h file, and found the the following line was commended out:

> NOT 已注释掉。 stdlib.h的部分应该是这样:

It should NOT be commented out. That part of stdlib.h should look like this:

#ifndef _CRT_TERMINATE_DEFINED
#define _CRT_TERMINATE_DEFINED
_CRTIMP __declspec(noreturn) void __cdecl exit(_In_ int _Code);
_CRTIMP __declspec(noreturn) void __cdecl _exit(_In_ int _Code);
_CRTIMP __declspec(noreturn) void __cdecl abort(void);
#endif

目前尚不清楚如何在您的版本文件。但很显然,你不必犹豫编辑编译器头文件以摆脱一个问题。你可能已经这样做,以绕过问题,不记得它。

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.

一般来说,这是一个真正的坏主意。 Microsoft发布将更新编译器头文件的Service Pack和安全更新。但是如果文件被修改,它不会这样做。

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.

这篇关于当在vs2010中使用iostream时,我得到错误C2039:'exit':不是'`全局命名空间''的成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆