std::to_string in C++ Last Updated : 24 Sep, 2024 Comments Improve Suggest changes Like Article Like Report In C++, the std::to_string function is used to convert numerical values into the string. It is defined inside <string> header and provides a simple and convenient way to convert numbers of any type to strings.In this article, we will learn how to use std::to_string() in C++.Syntaxstd::to_string(val);Parametersval: It is the value which we have to convert into string. It can be of any numeric data type like integer, long long, double, float, long double.Return ValueA string containing the representation of val as a sequence of characters.Example of std::to_string() C++ // C++ Program to show how to use std::to_string // for converting any numerical value #include <bits/stdc++.h> using namespace std; int main() { int num = 42; double pi = 3.14159; float fnum = 1.234f; // Converts integer to string string str1 = to_string(num); // Converts double to string string str2 = to_string(pi); // Converts float to string string str3 = to_string(fnum); cout << "Numbers as String: " << endl; cout << str1 << endl; cout << str2 << endl; cout << str3 << endl; return 0; } OutputNumbers as String: 42 3.141590 1.234000 Comment More info R Rohit Thapliyal Improve Article Tags : Misc C++ STL cpp-strings-library Explore C++ BasicsIntroduction to C++3 min readData Types in C++6 min readVariables in C++4 min readOperators in C++9 min readBasic Input / Output in C++5 min readControl flow statements in Programming15+ min readLoops in C++7 min readFunctions in C++8 min readArrays in C++8 min readCore ConceptsPointers and References in C++5 min readnew and delete Operators in C++ For Dynamic Memory5 min readTemplates in C++8 min readStructures, Unions and Enumerations in C++3 min readException Handling in C++11 min readFile Handling through C++ Classes8 min readMultithreading in C++8 min readNamespace in C++5 min readOOP in C++Object Oriented Programming in C++8 min readInheritance in C++6 min readPolymorphism in C++5 min readEncapsulation in C++4 min readAbstraction in C++4 min readStandard Template Library(STL)Standard Template Library (STL) in C++3 min readContainers in C++ STL3 min readIterators in C++ STL10 min readC++ STL Algorithm Library3 min readPractice & ProblemsC++ Interview Questions and Answers1 min readC++ Programming Examples4 min read Like