打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
#include<iostream>和#include<iostream.h>的区别

http://blog.sina.com.cn/s/blog_4a84e45b0100f576.html

区别在于:如果用了<iostream>,则一定要引入命名空间,即"using  namespace  std;如果用了<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 
   
  //情况三:使用<iostream.h>,引入命名空间,这时候编译出错 
  #include  <iostream.h> 
  using  namespace  std; 
  int  main() 
 
     cout<<"<iostream>  need  to  use  namespace  std!\n"; 
     return  0; 
 
  编译错误信息: 
  error  C2871:  'std'  does  not  exist  or  is  not  namespace 
   从功能性的角度来讲,<iostream>包含了一系列模板化的I/O类,相反地<iostream.h>只仅仅是支持字符流。另外,输入输出流的C++标准规范接口在一些微妙的细节上都已改进,因此,<iostream>和<iostream.h>在接口和执行上都是不同的。最后,<iostream>的各组成都是以STL的形式声明的,然而<iostream.h>的各组成都是声明成全局型的。
严格来说,不带h的用法是纯C++的标准用法,主要是配合STL库使用的。如果你的程序要使用C库,那么就要带.h。因此第一种和第二种写法,最大的区别在于你使用C模式还是纯C++模式。还有比如<string.h>是旧的C头文件,对应的是基于char*的字符串处理函数;<string>是包装了std的C++头文件,对应的是新的strng类;<cstring>是对应旧的C头文件的std版本。

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
关于“using namespace std”
C 中的std详解
C++命名空间(壹)
两个数较大值如何求取
【C 】数组讲解之二维数组
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服