一、数字转为 string 类型

借用 sprintf 函数:

char buffer[256];
int counter = 10;
sprintf(buffer,"%04i", counter);
std::string number = std::string(buffer);

二、string 类型转为数字

C 标准库提供了 atoi, atof, atol, atoll(C++ 11标准)函数将 char* 字符串转换成 int, double, long, long  long 型:

char    str[] = "15.455";
double db;
int i;
db = atof(str); // db = 15.455
i = atoi(str); // i = 15

若字符串为 string 类型。则要用 c_str() 方法先转化为 char* 字符串。例如以下:

string    str = "15.455";
double db;
int i;
db = atof(str.c_str()); // db = 15.455
i = atoi(str.c_str()); // i = 15

最新文章

  1. jquery使用案例
  2. Intent跳转传list集合
  3. thinkphp 调用系统的方法
  4. lower_bound 和 upper_bound
  5. 抽屉显示控件SlidingDrawer入门
  6. maven依赖传递关系
  7. 用DIV+Css+Jquery 实现的旧版微信飞机大战。
  8. self和super之间的区别
  9. testNg官方文档
  10. c语言实现动态指针数组Dynamic arrays
  11. mysql 初始化时root无密码
  12. Ubuntu下关闭防火墙
  13. TSQL:A表字段与B表中的关联,关联条件中一列是随机关联的实现方式
  14. SQLServer之修改索引
  15. springboot情操陶冶-SpringApplication(一)
  16. Centos 6.x 升级到 7.x
  17. Linux:ldd命令详解
  18. oracle体系结构理解
  19. Druid连接池(三)
  20. [usaco]2013-jan Liars and Truth Tellers 真假奶牛

热门文章

  1. crm 系统项目(二) admin 后台操作表格
  2. javascript深度克隆函数deepClone
  3. JStorm中的并行( parallelismction )介绍
  4. web前端project师知识汇总
  5. shadowOffset 具体解释
  6. Cordova 5 架构学习 Weinre远程调试技术
  7. ES不设置副本是非常脆弱的,整个文章告诉了你为什么
  8. HBA卡
  9. web.xml配置详解(转载)
  10. e.Row.Attributes.Add