std::stoi (and variants for each numeric type) and
std::to_string, the counterparts of the C
itoa but expressed in term of
#include <string> std::string s = std::to_string(42);
is therefore the shortest way I can think of. You can even omit naming the type, using the
auto s = std::to_string(42);
Note: see [string.conversions] (21.5 in n3242)
- Easiest way to convert int to string in C++
- How can I convert a std::string to int?
- How to convert a number to string and vice versa in C++
- What happens if I assign a negative value to an unsigned variable?
- C++ performance challenge: integer to std::string conversion
- How to convert integer to string in C? [duplicate]
- How to convert string to char array in C++?
- Convert String containing several numbers into integers
- How can I create a string from a single character?
- C++ floating point to integer type conversions
- Converting a String to DateTime
- What is the type of string literals in C and C++?
- Case-insensitive string comparison in C++ [closed]
- How to concatenate a std::string and an int
- How can I use cout
- Why should one not derive from c++ std string class?
- Why does omission of “#include ” only sometimes cause compilation failures?
- Conveniently Declaring Compile-Time Strings in C++
- How to convert an instance of std::string to lower case
- Converting std::__cxx11::string to std::string
- Difference between string and char types in C++
- stringstream, string, and char* conversion confusion
- How do I check if a C++ string is an int?
- What is the difference between (type)value and type(value)?
- C-Style Strings as template arguments? [duplicate]
- Is string::c_str() no longer null terminated in C++11?
- Efficient way to determine number of digits in an integer
- Two string literals have the same pointer value?
- C++: Can a macro expand “abc” into ‘a’, ‘b’, ‘c’?
- C++ Compare char array with string
- C++ function to count all the words in a string
- What am I not understanding about getline+strings?
- C++ string to enum
- How to reverse an std::string? [duplicate]
- How to convert string to integer in C#
- performance of unsigned vs signed integers
- Error: invalid operands of types ‘const char ’ and ‘const char ’ to binary ‘operator+’
- C++ string::find complexity
- How to check if the input is a valid integer without any other chars?
- Converting String To Float in C#
- reading a line from ifstream into a string variable
- writing directly to std::string internal buffers
- What is the datatype of string literal in C++?
- How to convert a char array to a string?
- splitting a string into an array in C++ without using vector
- Difference between long and int data types [duplicate]
- Do I have to use #include beside ?
- “” + something in C++
- Get bytes from std::string in C++
- What’s the difference between istringstream, ostringstream and stringstream? / Why not use stringstream in every case?