Chinaunix首页 | 论坛 | 博客
  • 博客访问: 6086577
  • 博文数量: 2759
  • 博客积分: 1021
  • 博客等级: 中士
  • 技术积分: 4091
  • 用 户 组: 普通用户
  • 注册时间: 2012-03-11 14:14
文章分类

全部博文(2759)

文章存档

2019年(1)

2017年(84)

2016年(196)

2015年(204)

2014年(636)

2013年(1176)

2012年(463)

分类: C/C++

2014-06-06 02:43:30

原文地址:C++11中的to_string 作者:Aquester

C++11之前,标准库没有提供数字类型转字符串的函数,需要借助sprintf、stringstream等,现在C++11提供了std::to_string函数,可以直接使用了:

点击(此处)折叠或打开

  1. string to_string (int val);
  2. string to_string (long val);
  3. string to_string (long long val);
  4. string to_string (unsigned val);
  5. string to_string (unsigned long val);
  6. string to_string (unsigned long long val);
  7. string to_string (float val);
  8. string to_string (double val);
  9. string to_string (long double val);

除此之外,C++11标准库还引入了字符串转整数系列函数:

点击(此处)折叠或打开

  1. int stoi (const string& str, size_t* idx = 0, int base = 10);
  2. long stol (const string& str, size_t* idx = 0, int base = 10);
  3. long long stoll (const string& str, size_t* idx = 0, int base = 10);
  4. unsigned long stoul (const string& str, size_t* idx = 0, int base = 10);
  5. unsigned long long stoull (const string& str, size_t* idx = 0, int base = 10);
  6. double stod (const string& str, size_t* idx = 0);
  7. float stof (const string& str, size_t* idx = 0);




阅读(698) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~