什么是“using namespace std”的用法? [英] What is the use of "using namespace std"?

查看:164
本文介绍了什么是“using namespace std”的用法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用命名空间std 的用途是什么?

我想在Layman中看到解释。​​

I'd like to see explanation in Layman terms.

推荐答案


  • 使用:您将要使用

  • 命名空间命名空间

  • std std 命名空间(其中C ++标准库的功能, code> string 或向量)。

    • using: You are going to use it
    • namespace: To use what? A namespace
    • std: The std namespace (where features of the C++ Standard Library, such as string or vector, are declared).
    • 编写此指令后,如果编译器看到 string ,它会知道你可能引用 std :: string ,如果它看到向量,它会知道你可能指的是 std :: vector

      After you write this instruction, if the compiler sees string it will know that you may be referring to std::string, and if it sees vector, it will know that you may be referring to std::vector. (Provided that you have included in your compilation unit the header files where they are defined, of course.)

      如果您不要写入,那么您的编译单元中已经包含了它们定义的头文件。它,当编译器看到 string 向量时,它不会知道你正在引用。你需要明确告诉它 std :: string std :: vector ,如果你不,你会得到一个编译错误。

      If you don't write it, when the compiler sees string or vector it will not know what you are refering to. You will need to explicitly tell it std::string or std::vector, and if you don't, you will get a compile error.

      这篇关于什么是“using namespace std”的用法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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