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

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

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

itoa是把整型转成char*,如果要转成string类型的话,可以用如下方法

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

来自:http://notfaq.wordpress.com/2006/08/30/c-convert-int-to-string/

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

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

Avatar_small
弹琴的企鹅 说:
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. https://www.posterprintcenter.com/


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter