See the N3242 Working Draft of C++11, chapter 21.5 Numeric Conversions.
There are some useful functions, such as string to_string(int val);
mentioned but I don't understand how they're called. Can anyone give me an example please?
Those functions are in the header <string>
. You just call them like any other function:
#include <string>
std::string answer = std::to_string(42);
GCC 4.5 already supports those functions, you just need to compile with the -std=c++0x
flag.
Sure:
std::string s = std::to_string(123); // now s == "123"
These functions use sprintf
(or equivalent) internally.
They are called like any other function:
int number = 10;
std::string value;
value = std::to_string(number);
std::cout << value;
To call them you will need a C++ compiler that supports the draft recommendations (VS2010 and GCC4+ I think support them).
精彩评论