Chinaunix首页 | 论坛 | 博客
  • 博客访问: 750298
  • 博文数量: 217
  • 博客积分: 2401
  • 博客等级: 大尉
  • 技术积分: 2030
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-16 06:58
个人简介

怎么介绍?

文章分类

全部博文(217)

文章存档

2023年(2)

2022年(3)

2021年(29)

2020年(12)

2019年(5)

2018年(5)

2017年(5)

2016年(3)

2015年(6)

2014年(12)

2013年(16)

2012年(9)

2011年(6)

2010年(15)

2009年(30)

2008年(59)

我的朋友

分类:

2008-09-23 08:33:44

C++ -- Conver string to int

string s;
float f;
stringstream ss;
ss << s;
ss >> f;

C++ — Convert int to string

In order to convert an int (or any other numeric type, e.g., float, double, etc.) to string, you can use:

#include

int i = 5;
std::string s;
std::stringstream out;
out << i;
s = out.str();

Other not so frequently asked questions.

8 Responses to “C++ — Convert int to string”

  1. Says:

    Here’s a more generic version:

    #include

    template
    inline std::string to_string (const T& t)
    {
    std::stringstream ss;
    ss << t;
    return ss.str();
    }

阅读(2224) | 评论(0) | 转发(0) |
0

上一篇:隔夜黄莺

下一篇:VC++ link options

给主人留下些什么吧!~~