CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
山寨机中的战斗机! 程序优化工程师到底对IT界有没有贡献
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VC/MFC >  基础类

#include <string>

楼主linxiao()2002-04-17 14:21:39 在 VC/MFC / 基础类 提问

#include   <string>  
  //using   namespace   std;       //1,不要这句也能通过,这是为什么?  
  int   main()  
  {  
  char   *p   =   NULL;  
  return   0;  
  }  
   
   
  2,找到NULL的定义后:  
  .#ifdef     __cplusplus       //如果没有定义__cplusplus        
    #define   NULL         0             //则定义NULL   为   0  
    #else                                     //否则定义NULL为((void   *)0)  
    #define   NULL         ((void   *)0)  
    #endif  
  什么时候要定义:__cplusplus 问题点数:50、回复次数:12Top

1 楼qfpcn(ξ幽灵ξ)回复于 2002-04-17 14:36:43 得分 5

这是系统做的事,不用你管。Top

2 楼yg_xh(果皮)回复于 2002-04-17 14:49:16 得分 10

1.这是c++新的库为了兼容原有的函数库所以提供了两个版本的函数,为了区别就把新的库定义在名字空间std下,可以这样用std::xxx,所以你的程序可以通过;  
  2.不知道Top

3 楼linxiao()回复于 2002-04-17 14:55:07 得分 0

yg_xh(果皮):  
  不要using   namespace   std;我的程序也能通过啊?  
  我是<string>不是<string.h>Top

4 楼jimmyxu()回复于 2002-04-17 15:14:03 得分 15

There   is   a   file   named   "string",   which   can   be   found   by   VC.   In   fact   it   is   a   convention   to   C++,   and   string.h   is   the   standard   or   older   header   file   of   ANSI   C.   And   C++   has   rewritten   it   using   string,   without   suffix   .h,   to   tell   you   their   difference.   To   C++,   the   standard   string.h   is   renamed   to   cstring,   that   is,   when   you   include   cstring,   in   fact   you   include   the   string.h.   Of   course,   the   string.h   has   still   existed,   especially   to   ANSI   C   user.   So   you   can   write   what   you   wrote   above   and   realize   what   you   want.   But,   the   best   practice   is   to   using   cstring   in   C++   program,   and   use   string.h   in   C   program.    
   
  As   of   the   statement  
   
  using   namespace   std;  
   
  it   is   another   practice,   which   will   be   allowed   to   use   function   defined   in   namespace   std,   that   is   to   use  
   
  std::xxx    
   
  Nothing   else.Top

5 楼jimmyxu()回复于 2002-04-17 15:16:50 得分 5

Sorry   for   my   mistaken.  
   
  If   you   use   using   directive   using,   you   can   use   cout,   cin   etc   without   appending   std::;   else   you   should   add!  
  Top

6 楼mickeyfirst(黑梦)回复于 2002-04-17 15:17:22 得分 5

__cplusplus是用来判断是不是符合C++规范。Top

7 楼programCat()回复于 2002-04-17 16:13:06 得分 5

你又没有声明一个string类,当然能通过了啊。  
  你试着写一句  
  string   s;   看看  
  保证你通不过。当你使用string的时候,你必须得加using   namespace   std;Top

8 楼linxiao()回复于 2002-04-18 11:48:56 得分 0

programcat():  
  你的意思是   #include   <string>   没有派上用场?在这个程序中是可有可无的?但是你把   #include   <string>   去掉,那个程序就编译通不过了  
   
   
  Top

9 楼programCat()回复于 2002-04-24 09:13:23 得分 5

那是因为你去掉<string>之后,NULL没有定义。  
  你可以自己定义  
  加上const   int   NULL=0;这句Top

10 楼linxiao()回复于 2002-05-11 14:44:13 得分 0

我以为下面两句是要一起用的:  
  #include   <string>  
  using   namespace   std;        
  但这道题中,确可以不要using   namespace   std;     这是为什么?  
   
  Top

11 楼linxiao()回复于 2002-05-13 10:00:02 得分 0

????Top

12 楼linxiao()回复于 2002-05-29 15:52:01 得分 0

我以为下面两句是要一起用的:      
  #include         <string     >      
  using     namespace     std;                  
  但这道题中,确可以不要using     namespace     std;         这是为什么?      
  Top

相关问题

  • #include <string>与#include <string.h>
  • 关于include<string>的问题
  • string
  • String
  • string
  • string->???
  • string
  • string
  • String
  • #include <string>和#include <string.h>有何区别?

关键词

  • c++
  • null
  • 定义
  • namespace std
  • cplusplus
  • 程序
  • 库
  • cstring
  • std
  • 能通过

得分解答快速导航

  • 帖主:linxiao
  • qfpcn
  • yg_xh
  • jimmyxu
  • jimmyxu
  • mickeyfirst
  • programCat
  • programCat

相关链接

  • Visual C++类图书
  • Visual C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo