在C++11中可以使用std::to_string()函数将数值转换为string格式,十分方便。

以下部分来选自cplusplus.com

std::to_string

string to_string (int val);
string to_string (long val);
string to_string (long long val);
string to_string (unsigned val);
string to_string (unsigned long val);
string to_string (unsigned long long val);
string to_string (float val);
string to_string (double val);
string to_string (long double val);
Convert numerical value to string

Returns a string with the representation of val.

示例

// to_string example
#include <iostream> // std::cout
#include <string> // std::string, std::to_string int main ()
{
std::string pi = "pi is " + std::to_string(3.1415926);
std::string perfect = std::to_string(++++) + " is a perfect number";
std::cout << pi << '\n';
std::cout << perfect << '\n';
return ;
}

输出

pi is 3.141593

28 is a perfect numbe

参考资料

[1]http://www.cplusplus.com/reference/string/to_string/

转载请注明来自:田小777-博客园

原文地址:http://www.cnblogs.com/kitian616/p/4763578.html

如若转载,请保留原文地址。谢谢合作。

C++11中int,float,double与string的转化的更多相关文章

  1. 关于c中 int, float, double转换中存在的精度损失问题

    先看一段代码实验: #include<limits> #include<iostream> using namespace std; int main() { unsigned ...

  2. Android中 int,float,Double,String 互相转换

    1 如何将字串 String 转换成整数 int?  A. 有两个方法: 1). int i = Integer.parseInt([String]); 或 i = Integer.parseInt( ...

  3. QT中QString 与 int float double 等类型的相互转换

    Qt中 int ,float ,double转换为QString 有两种方法 1.使用 QString::number(); 如: long a = 63; QString s = QString:: ...

  4. java中int,float,long,double取值范围,内存泄露

    java中int,float,long,double取值范围是多少? 写道 public class TestOutOfBound { public static void main(String[] ...

  5. C++中将string类型转换为int, float, double类型 主要通过以下几种方式:

      C++中将string类型转换为int, float, double类型 主要通过以下几种方式: # 方法一: 使用stringstream stringstream在int或float类型转换为 ...

  6. [C++] string与int, float, double相互转换

    参考:http://blog.csdn.net/candadition/article/details/7342380 将string类型转换为int, float, double类型 主要通过以下几 ...

  7. MySQL中 DECIMAL FLOAT DOUBLE的区别

    第一篇文章: MySQL中Decimal类型和Float Double等区别 MySQL中存在float,double等非标准数据类型,也有decimal这种标准数据类型. 其区别在于,float,d ...

  8. C 语言实例 - 计算 int, float, double 和 char 字节大小

    C 语言实例 - 计算 int, float, double 和 char 字节大小 C 语言实例 C 语言实例 使用 sizeof 操作符计算int, float, double 和 char四种变 ...

  9. sql server数据库如何存储数组,int[]float[]double[]数组存储到数据库方法

    原文地址:https://www.zhaimaojun.top/Note/5475296 将数组存储到数据库的方法 (本人平时同csharp编写代码,所以本文中代码都是csharp代码,有些地方jav ...

随机推荐

  1. LA 4726 再看斜率优化

    感觉最近一批解题报告没写,现在慢慢补吧,算是noip前攒攒rp了 首先感到深深的自责,因为之前对斜率优化没有深入的理解,只是记住了一般步骤,并没有完全了解为什么这样做 先就这道题目而言 首先这种序列题 ...

  2. 【转】Android4.3 蓝牙BLE初步

    原文网址:http://www.cnblogs.com/savagemorgan/p/3722657.html 一.关键概念: Generic Attribute Profile (GATT) 通过B ...

  3. (转载)MySQL 统计数据行数 Select Count

    (转载)http://www.5idev.com/p-php_mysql_select_count.shtml 统计数据行数 SELECT COUNT() FROM 语法用于从数据表中统计数据行数. ...

  4. Python根据上下限生成不重复随机数

    Python 2.7.5 代码: # coding=gbk import random import sys min_num = input('输入下限:') max_num = input('输入上 ...

  5. Search Insert Position——LeetCode

    Given a sorted array and a target value, return the index if the target is found. If not, return the ...

  6. MySQL选用可重复读之前一定要想到的事情

    原文地址:http://blog.itpub.net/29254281/viewspace-1398273/ MySQL选用可重复读隔离级别之前一定要想到的事情.间隙锁 MySQL在使用之前有三个务必 ...

  7. First Record

    今天我在博客园安家了! R Python Scala hadoop Spark MachineLearning

  8. HashTable和HashMap的区别

    1.HashTable线程安全,同步,效率相对低下. HashMap线程不安全,非同步,效率相对高 2.父类:HashTable的父类是Dictionary HashMap是AbstractMap 3 ...

  9. AABB包围盒、OBB包围盒、包围球的比較

    1) AABB 包围盒: AABB 包围盒是与坐标轴对齐的包围盒, 简单性好, 紧密性较差(尤其对斜对角方向放置的瘦长形对象, 採用AABB, 将留下非常大的边角空隙, 导致大量不是必需的包围盒相交測 ...

  10. TCP具体解释(3):重传、流量控制、拥塞控制……

    传输数据 在TCP的数据传送状态.非常多重要的机制保证了TCP的可靠性和强壮性.它们包括:使用序号.对收到的TCP报文段进行排序以及检測反复的数据:使用校验和来检測报文段的错误.使用确认和计时器来检測 ...