See the following code, debug and show convert is successful on both iPhone simulator and device (4S), but I wonder how does it work? See http://www.cplusplus.com/reference/iostream/ostream/operator%3C%3C/, no overload function for boost::int64_t.
Any risk if I use this function to convert any arbitrary boost::int64_t type? Thanks in advance.
std::stringstream mySS;
boost::int64_t large = 4294967296889977;
mySS<<large;
std::string str = mySS.str();
The reason it works is that
boost:int64_tis really a typedef to a built-in type (typicallystd::int64_tdefined incstdintor something like that), so it probably ends up being the same aslong long(or similar, depending on the platform). Of course there is an overload ofstringstream::operator<<for that.For the exact definition, best see
boost/cstdint.hpp(1.51 version).It is probably a relatively safe bet to assume that this will generally work on all major platforms. But I doubt anyone will be able to give a guarantee for that.
If the purpose of your using
std::stringstreamis to convert between integers and strings, the safest thing you can do is simply to use Boost’s own way of converting:boost::lexical_cast(1.51 version). Here is how it’s done: