用g++编译最简单的C++程序hello.C出现可以用-Wno-deprecated屏蔽的警告,想问个究竟

 

程序如下:  
  #include   <iostream.h>  
   
  main   ()  
  {  
          cout   <<   "hello,   world!"   <<   endl;  
  }  
   
   
  警告如下:  
  in   file   included   from   /usr/include/c++/3.2.2/backward/iostream.h:31,  
                                    from   hello.c:1:  
  /usr/include/c++/3.2.2/backward/backward_warning.h:32:2:   warning:    
  #warning   this   file   includes   at   least   one   deprecated   or   antiquated   header.    
  please   consider   using   one   of   the   32   headers   found   in   section   17.4.1.2   of   the   c++   standard.  
  examples   include   substituting   the   <x>   header   for   the   <x.h>   header   for   c++   includes,   or   <sstream>   instead   of    
  the   deprecated   header   <strstream.h>.   to   disable   this   warning   use   -wno-deprecated.  
   
  出现上面的警告是什么原因,要怎么解决才可以不用-wno-deprecated参数直接编译。   
 

网友:blh

c++的程序和c时有区别的,修改如下  
  #include   <iostream>  
  using   namespace   std;  
   
  main   ()  
  {  
          cout   <<   "hello,   world!"   <<   endl;  
  }   

网友:ybei

<iostream.h>是老的c++函数库,g++建议你使用新的<iostream>  
  使用方法就像楼上说的  
  要注意using   namespace   std   不能省

 

网友:interbanker

#include   <iostream.h>  
   
  main   ()  
  {  
          cout   <<   "hello,   world!"   <<   endl;  
  }  
  ------------------------------------  
  当使用gcc编译的时候提示出错:  
  gcc   hello.cpp   -o   hello  
  undefined                                               first   referenced  
    symbol                                                           in   file  
  endl(ostream   &)                                           /usr/tmp/cckxbuns.o  
  ostream::operator<<(ostream   &(*)(ostream   &))/usr/tmp/cckxbuns.o  
  cout                                                                 /usr/tmp/cckxbuns.o  
  ostream::operator<<(char   const   *)       /usr/tmp/cckxbuns.o  
  hello:   fatal   error:   symbol   referencing   errors.   no   output   written   to   hello  
  collect2:   ld   returned   1   exit   status  
   
  当使用g++编译  
  g++   hello.cpp   -o   hello  
  编译通过,  
  我把hello.cpp改成hello.c,还是用g++   hello.c   -o   hello,编译通过  
  综上所述,编译不通过的原因不是因为命名空间的问题。  
  因为gcc编译的是c语言,g++编译的是c++程序。  
   
   
  另注:        
    gcc         assumes   preprocessed   (.i)   files   are   c   and   assumes   c  
                              style   linking.  
   
    g++         assumes   preprocessed   (.i)   files   are   c++   and   assumes  
                              c++   style   linking.  
   
   
 

网友:onlymilan

#include   <iostream.h>   是window下的  
   
  #include   <iostream>  
  using   namespace   std;     这才是unix/linux下的

网友:fierygnu

呵呵。  
  老c++用.h做头文件,没有namespace   std,新标准规定不要.h,有namespace。这个跟平台没关系,跟编译器实现遵循的标准有关系。

网友:onlymilan

命名空间是新的c++标准中的,新版本的c++编译器支持命名空间,unix/linux下的g++都支持  
  所以,在unix/linux下这样写  
   
  #include   <iostream>  
  using   namespace   std;  
   
  绝对不会有警告。  
   
  而在windows   vc++   下这样写  
   
  #include   <iostream>  
  using   namespace   std;  
   
  就会出错。如果使用#include   <iostream.h>就没问题。  
  而在unix/linux下使用#include   <iostream.h>就会出警告,因为这是老版本的c++标准 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值