码迷,mamicode.com
首页 > 移动开发 > 详细

关于iostream和c++命名空间

时间:2018-03-01 23:30:45      阅读:209      评论:0      收藏:0      [点我收藏+]

标签:spec   gpo   red   命名   使用方法   nbsp   ali   ++   必须   

c++标准库函数都在std这个命名空间中,想要使用必须加上using namespace std,下面给出几种使用方法

1. specify the identifier directily, for example std::ostream instead of ostream. the complete sentence is as follows:

std :: cout << std :: hex << 3.4 << std :: endl;

2. using the "suing" key word

using std :: cout;
using std :: endl;
The above code can be written as
cout << std :: hex << 3.4 << endl;

3. the most convenient is to useing namespace std

 

all identifier defined in namespace std are valid, as if they were declared as global varibales. Then the above statement can be written as follows:

cout << "i didn‘t pass the cet four" << "ma mai pi";

关于iostream和c++命名空间

标签:spec   gpo   red   命名   使用方法   nbsp   ali   ++   必须   

原文地址:https://www.cnblogs.com/1915884031A-qqcom/p/8490696.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!