使用命名空间std会做什么?做? [英] What does using namespace std; do?
本文介绍了使用命名空间std会做什么?做?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
此C ++代码有什么问题?
What is the matter with this C++ code?
我收到一条错误消息,提示:在 z
之前应该有一个;
,这是不正确的.我唯一不了解的是目的行2的服务.
I get an error message saying: that there should be a ;
before z
, which is not correct. The only part that I don't understand is the purpose line 2 serves.
#include <iostream>
using namespace std;
int subtraction(int a, int b)
{
int r;
r=a-b;
return r;
}
int main()
{
int z;
z = subtraction (5,9);
cout z;
}
谢谢.
推荐答案
使用命名空间std;
意味着您以后可以编写 cout
而不是 std ::cout
.它省去了键入操作,而牺牲了命名空间的严重污染.
using namespace std;
means you can write cout
later on rather than std::cout
. It saves typing at the expense of gross namespace pollution.
您的编译错误可以通过编写 cout<<z;
Your compile error can be fixed by writing cout << z;
另外,请从
Also, do return a value from main
.
这篇关于使用命名空间std会做什么?做?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文