Converting between numeric and string types
Converting between number and string types is a ubiquitous operation. Prior to C++11, there was little support for converting numbers to strings and back, so developers had to resort mostly to type-unsafe functions, and they usually wrote their own utility functions in order to avoid writing the same code over and over again. With C++11, the standard library provides utility functions for converting between numbers and strings. In this recipe, you will learn how to convert between numbers and strings and the other way around using modern C++ standard functions.
All the utility functions mentioned in this recipe are available in the
How to do it...
Use the following standard conversion functions when you need to convert between numbers and strings:
- To convert from an integer or floating-point type to a string type, use
std::to_wstring(), as shown in the...