将int转换为std :: string [英] Converting an int to std::string

查看:115
本文介绍了将int转换为std :: string的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是最短的方式,最好是inline-able,将int转换为字符串?欢迎使用stl和boost的答案。

What is the shortest way, preferably inline-able, to convert an int to a string? Answers using stl and boost will be welcomed.

推荐答案

boost :: lexical_cast< std :: string& (yourint) boost / lexical_cast.hpp

:ostream支持,但不像例如 itoa

Work's for everything with std::ostream support, but is not as fast as, for example, itoa

那么快,它甚至看起来比stringstream或scanf:

It even appears to be faster than stringstream or scanf:

  • http://www.boost.org/doc/libs/1_53_0/doc/html/boost_lexical_cast/performance.html

这篇关于将int转换为std :: string的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆