设为首页 加入收藏

TOP

C++如何将数字(包括double型)转换为字符串
2014-10-23 15:30:04 来源: 作者: 【 】 浏览:55
Tags:如何 数字 包括 double 转换 字符串


  #define toString(x) #x这个宏就可以将所有的数字,包括int型、long型和double型转换为相对应的字符串。关于这种类似的用法还有:


  #define makechar(x) #@x


  a = makechar(b);


  #define stringer( x ) printf( #x "\n" )


  void main()


  {


  stringer( In quotes in the printf function call\n );


  stringer( "In quotes when printed to the screen"\n );


  stringer( "This: \" prints an escaped double quote" );


  }


  //预处理时将会产生如下代码。


  void main()


  {


  printf( "In quotes in the printf function call\n" "\n" );


  printf( "\"In quotes when printed to the screen\"\n" "\n" );


  printf( "\"This: \\\" prints an escaped double quote\"" "\n" );


  }


  运行结果:


  In quotes in the printf function call


  "In quotes when printed to the screen"


  "This: \" prints an escaped double quotation mark"


  这种用法可以省去转义字符(\),很方便代码的编写。


  关于#的用法还有很多,希望有兴趣的读者能够留言,我们一起讨论。


  编辑特别推荐:


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇C++kmp算法模板代码解读 下一篇VC++数据库通用模块:公用模块设计

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: