Found out C++11 has the following two gems:

Found out C++11 has the following two gems:

 

std::stoi, std::stol, std::stoll , std::stof, std::stod, std::stold, std::stof, std::stod, std::stold  – Coverts a C++ string to numeric type. Similar to the good old atoi, atod, atof but take C++ strings so you don’t need to add .c_str() to each one. Saves a few keystrokes and looks neater.

std::to_string – converts a numeric type to a string. This is useful as it saves a few lines from converting via sprinf or streambuf.

They work on gcc 4.8.1 with Ubuntu 13.10. 

CAVEAT: So I started using them in some new code, only to discover that they don’t work on my buildroot cross-compiler environment which is on gcc 4.8.0 (although 4.8.0 supports other C++11 features). Seems MINGW users are having the same issues also. Spent the last hour reverting my code. 8-(

#C++11


LINK:

std::to_string()
 


This post was originally published publicly on Google+ at 2013-12-15 19:03:38+0800

You may also like...