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?


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.

  • 9
    Which leaves the question why the stoX functions were named such awkwardly instead of providing a matching generic from_string<T> specialized for each arithmetic type T.
    – 5gon12eder
    Mar 9 '16 at 1:59
  • 1
    Probably following on from C Feb 1 '17 at 22:37
  • 5
    to_string is not the exact opposite of stoi, bacause in stoi() you can specify base, but in to_string() you cant :/ Sep 13 '18 at 3:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.