What is the use of quot;using namespace stdquot;?(“使用命名空间标准有什么用?)
问题描述
using namespace std有什么用?
我希望看到通俗易懂的解释.
I'd like to see explanation in Layman terms.
推荐答案
- 使用:您将使用它.
- 命名空间:使用什么?命名空间.
- std:
std命名空间(C++ 标准库的特性,例如string或vector, 被声明). - using: You are going to use it.
- namespace: To use what? A namespace.
- std: The
stdnamespace (where features of the C++ Standard Library, such asstringorvector, are declared).
写完这条指令后,如果编译器看到string,它就会知道你可能指的是std::string,如果它看到vector,它会知道你可能指的是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或vector时它不会知道你指的是什么.你需要明确告诉它 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.
这篇关于“使用命名空间标准"有什么用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:“使用命名空间标准"有什么用?
基础教程推荐
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- CString 到 char* 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
