算道网-算道算法竞赛社
首页
个人中心
博客区
博客列表
我的博客
新闻
科创中心
网盘
共享网盘
个人网盘
算道新质AI平台额度购买
购买AI额度
我的礼品码
证书查询
关于我们
用户列表
登录
一键已读
删除已读
暂无新消息
一键已读
删除已读
命名空间的using声明
进入博客主页
流星雨的诺言
📅 发布于:
2024-10-16
🔄 已更新:
2024-10-16
编辑文章
删除文章
复制 MD
复制 HTML
使用using声明可以在不需要加前缀namespace_name: :的情况下访问命名空间中的名字。 using声明的形式如下: using namespace: :name; 一旦使用了using声明,我们就可以直接引用名字,而不需要再引用改名字的命名空间: #include <string> #include<iostream> // using declarations states our intent touse these names from the namespace std using std: :cin; using std: :string; int main() { string s; // ok: string is now a synonym for std: :string cin>>s; // ok; cin is now a synonym for std: :cin cout<< s; //error: no using declaration;we must use full name std: :cout << s; // ok; explicitly use cout from namespace std 没有using声明,而直接使用命名空间中的名字的未限定版本是错误的,尽管有些编译器也许无法检测出这种错误
评论
提交
取消
发表评论
提交
×
评论