invalid conversion from ‘const char*’ to ‘char’

C++ —用sstream把int转成string类型的方法

Author posted @ 2011年9月15日 08:59 in C/C++ , 3905 阅读


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

#include <sstream>

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


Mike Manilone 说:
2011年9月17日 00:42

string str(itoa(123));
cout << str;

弹琴的企鹅 说:
2012年2月17日 15:57

@Mike Manilone: cool, 谢谢

Liwovosa 说:
2021年5月04日 20:38

Great post, you have pointed out some excellent points, I as well believe this is a very superb website. 123movie

SEO 说:
2022年2月25日 17:22

This is my first visit to your web journal! We are a group of volunteers and new activities in the same specialty. Website gave us helpful data to work.

登录 *

loading captcha image...
or Ctrl+Enter