Topic: Re: Why std::string doesn t include automatic conv?= =?windows-1252?Q?ersion from the standard primitives?


Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Tue, 20 Jul 2010 20:25:37 CST
Raw View
On Jul 6, 11:30 am, Peng Yu <pengyu...@gmail.com> wrote:
> In order to convert an int to a string, I have to write the following.
> #include <sstream>
> int i = 5;
> std::string s;
> std::stringstream out;
> out << i;
> s = out.str();
> I'm wondering why std::string doesn   t include automatic conversion
> from the standard primitives.
> For example, I won't be much concise to write the following than the
> above 5 lines of code. Can I suggest to add this in future C++
> standard? Where the suggestion should be sent to?
> std::string foo = 123

See 21.5 Numeric Conversions [string.conversions]/p7. You can write
that
as
std::string foo = std::to_string(123);
Coming soon to a c++0x implementation near you. :)


--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]