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);


​​

C++11中的to_string的更多相关文章

  1. C++中的to_string()函数[C++11支持]

    C++ -> 字符串库 -> std::basic_string 定义于头文件 std::string to_string(int value); (1) (C++11起) std::st ...

  2. C++11中int,float,double与string的转化

    在C++11中可以使用std::to_string()函数将数值转换为string格式,十分方便. 以下部分来选自cplusplus.com. std::to_string string to_str ...

  3. C++中的to_string()

    目录 C++中的to_string() 注:原创不易,转载请务必注明原作者和出处,感谢支持! C++中的to_string() C++中的 to_string()系列函数将数值转换成字符串形式.注意, ...

  4. 从linux0.11中起动部分代码看汇编调用c语言函数

    上一篇分析了c语言的函数调用栈情况,知道了c语言的函数调用机制后,我们来看一下,linux0.11中起动部分的代码是如何从汇编跳入c语言函数的.在LINUX 0.11中的head.s文件中会看到如下一 ...

  5. C++ 11 中的右值引用

    C++ 11 中的右值引用 右值引用的功能 首先,我并不介绍什么是右值引用,而是以一个例子里来介绍一下右值引用的功能: #include <iostream>    #include &l ...

  6. IOS中的Block与C++11中的lambda

    ios中的block 可以说是一种函数指针,但更确切的讲,其实际上其应该算是object-c对C++11中lambda的支持或者说是一个语言上的变体,其实际内容是一样的,C++的lambda我已经有简 ...

  7. 在Windows 8.1及IE 11中如何使用HttpWatch

    提示:HttpWatch现已更新至v9.1.8,HttpWatch v9.1及以上的版本现都已支持Windows 7,8,8.1和IE 11. 如果你的HttpWatch专业版授权秘钥允许进入vers ...

  8. C++11中对类(class)新增的特性

    C++11中对类(class)新增的特性 default/delete 控制默认函数 在我们没有显式定义类的复制构造函数和赋值操作符的情况下,编译器会为我们生成默认的这两个函数: 默认的赋值函数以内存 ...

  9. callable object与新增的function相关 C++11中万能的可调用类型声明std::function<...>

    在c++11中,一个callable object(可调用对象)可以是函数指针.lambda表达式.重载()的某类对象.bind包裹的某对象等等,有时需要统一管理一些这几类对象,新增的function ...

随机推荐

  1. 关于v$BH

    关于v$bh的相关字段值FILE# NUMBER Datafile identifier number (to find the filename, query DBA_DATA_FILES or V ...

  2. sqlserver并发处理,锁和事务

      本文系转载,谢谢:http://www.cnblogs.com/cxd4321/archive/2008/12/10/1351792.html     另外这个也不错 http://www.cnb ...

  3. zabbix agent主动模式与proxy模式,实现公网zabbix监控私网客户机

    zabbix agent主动模式,实现公网zabbix监控私网客户机 zabbix_server端当主机数量过多的时候,由Server端去收集数据,Zabbix会出现严重的性能问题,主要表现如下:  ...

  4. std::thread函数传参拷贝次数

    c++11的thread库大大方便了开发,但是目前网络上少有深入分析的资料和使用例程.特别是在线程函数传参这一块,一般止步于使用std::ref传引用. 这次写服务器遇到个BUG,线程函数参数是智能指 ...

  5. 36种漂亮的CSS3网页按钮Button样式

    <!DOCTYPE HTML> <html lang="en-US"> <head> <meta charset="UTF-8& ...

  6. zookeeper的概念和基础

    1.1ZooKeeper的使命 当开发人员使用ZooKeeper进行开发时,开发人员设计的那些应⽤往往可以看成成组连接到ZooKeeper服务器端的客户端,它们通过ZooKeeper的客户端API连接 ...

  7. 用django实现redirect的几种方法总结

    用django开发web应用, 经常会遇到从一个旧的url转向一个新的url.这种隐射也许有规则,也许没有.但都是为了实现业务的需要.总体说来,有如下几种方法实现 django的 redirect.1 ...

  8. dbf 命令 及数据类型

    left()函数只能截取左边几位字符,截取中间字符用SUBSTR() SUBSTR(cExpression, nStartPosition [, nCharactersReturned]) dbf u ...

  9. ajax传递给后台数组参数方式

    出自:http://blog.csdn.net/lingxyd_0/article/details/10428785 在项目上用到了批量删除与批量更改状态,前台使用了EasyUI的DataGrid,用 ...

  10. Fedora下安装Scrapy遇到的两个问题

    error:/usr/lib/rpm/redhat/redhat-hardened-cc1: No such file or directory 需要安装redhat-rpm-config sudo ...