使用命名空间std和库 [英] using namespace std and library

查看:66
本文介绍了使用命名空间std和库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我们需要头文件"和 using名称空间标记来使任何库函数正确执行.例如,除非我们使用 iostream ,否则 cout 将不起作用.除非我们使用"using namespace std",否则它将无法正常工作.我的问题是,为什么我们需要使用命名空间std 的以及 cout #include< iostream> 的组合才能成功执行?

Why we need both the "header file" and the using namespace tag for the any library function to get executed properly. For example cout will not work unless we use iostream. Also it will not work unless we use "using namespace std". My question is why do we need combination of both using namespace std as well as #include <iostream> for cout to execute successfully?

推荐答案

包含库标头可使该库功能对您的程序代码可见.否则,您的程序将不知道该库甚至存在.这是必需的部分.

Including a library header makes the library feature visible to your program code. Without that, your program has no idea that the library even exists. This is the part that is necessary.

使用命名空间std 编写只是允许您编写 cout ,而不是全名,即 std :: cout .这很方便,仅此而已.

Writing using namespace std simply allows you to write cout rather than the full name which is std::cout. It's a convenience, that's all.

这篇关于使用命名空间std和库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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