I noticed to my glee that C++11 has a std::sto@ family of functions for easily unpacking ints/floats/longs whatever from strings. I'm surprised however, that the opposite isn't implemented. Why didn't the standards committee include a std::itos family of functions for going from ints/floats/whatever (back) to strings?
Add a comment |
1 Answer
I was mistaken, there is a set of "Xtos" functions, they are all just named to_string. Each to_string is overloaded to take a different basic type, i.e.:
std::string to_string(float f); std::string to_string(int f); ... See here for more info.
- 10Which leaves the question why the
stoXfunctions were named such awkwardly instead of providing a matching genericfrom_string<T>specialized for each arithmetic typeT.5gon12eder– 5gon12eder2016-03-09 01:59:45 +00:00Commented Mar 9, 2016 at 1:59 - 1Probably following on from CMark K Cowan– Mark K Cowan2017-02-01 22:37:50 +00:00Commented Feb 1, 2017 at 22:37
- 6to_string is not the exact opposite of stoi, bacause in stoi() you can specify base, but in to_string() you cant :/Marin Shalamanov– Marin Shalamanov2018-09-13 03:15:53 +00:00Commented Sep 13, 2018 at 3:15