为了账号安全,请及时绑定邮箱和手机立即绑定

请问C++ iostream和iostream.h的区别是什么

请问C++ iostream和iostream.h的区别是什么

C++
函数式编程 2019-10-21 16:12:05
请问C++ iostream和iostream.h的区别是什么
查看完整描述

2 回答

?
慕妹3146593

TA贡献1820条经验 获得超9个赞

#include <iostream.h>非标准输入输出流

#include <iostream>标准输入输出流

C++中为了避免名字定义冲突,特别引入了“名字空间的定义”,即namespace。

当代码中用<iostream.h>时,输出可直接引用cout<<x;//<iostream.h>继承C语言的标准库文件,未引入名字空间定义,所以可直接使用。

当代码中引入<iostream>时,输出需要引用std::cout<<x;如果还是按原来的方法就会有错。

iostream.h是input output stream的简写,意思为标准的输入输出流头文件。它包含:

(1)cin>>"要输入的内容"

(2)cout<<"要输出的内容"

这两个输入输出的方法需要#include<iostream>头文件来声明。

iostream 库的基础是两种命名为 istream 和 ostream 的类型,分别表示输入流和输出流。流是指要从某种 IO 设备上读出或写入的字符序列。

扩展资料:

iostream和iostream.h的用法

使用<iostream>和命名空间 

#include <iostream> 

using namespace std; 

int main() 

cout<<"<iostream> need to use namespace std!/n"; 

return 0; 

输出: 

<iostream> need to use namespace std! 

Press any key to continue

使用<iostream.h>,不引入命名空间 

#include <iostream.h> 

//using namespace std; 

int main() 

cout<<"<iostream> need to use namespace std!/n"; 

return 0; 

输出: 

<iostream> need to use namespace std! 

Press any key to continue




查看完整回答
反对 回复 2019-10-22
?
繁花不似锦

TA贡献1851条经验 获得超4个赞

#include <iostream.h>非标准输入输出流
#include <iostream>标准输入输出流

C++中为了避免名字定义冲突,特别引入了“名字空间的定义”,即namespace。
当代码中用<iostream.h>时,输出可直接引用cout<<x;//<iostream.h>继承C语言的标准库文件,未引入名字空间定义,所以可直接使用。
当代码中引入<iostream>时,输出需要引用std::cout<<x;如果还是按原来的方法就会有错。
使用<iostream>时,引入std::有以下方法:

1.
using namespace std;
cout<<x;
2.
using std::cout;
cout<<x;
3.
最基本的std::cout<<x;

这回你该知道为什么通常用#include <iostream>时,
要用using namespace std;了吧。如果你不用这个,就要在使用cout时,用后两种方法了。
其他头文件也是同样的道理。
(有“.h”的就是非标准的,C的标准库函数,无“.h”的,就要用到命令空间,是C++的。还有一部分不完全是有“.h”和没“.h”的差别。例如:math.h和cmath)




查看完整回答
反对 回复 2019-10-22
  • 2 回答
  • 0 关注
  • 359 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信