How to Convert an Integer to a String in C++? Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report Integer and String are the two data types in C++ programming languages. An integer is generally used to represent the whole numbers in the number line. A String is a data structure that is used to save a collection of characters. It can be a word or a sentence. Moreover, it can also store the numerical characters representing an integer number. In this article, we are going to learn how to convert an integer to a string in C++. Example: Input: 42(Integer)Output: 42(String)How to Convert an Integer to a String in C++?To convert an int data type to a string data type, we can use the to_string() function. This function is a part of <string> header. This function is used to convert any data structure to a string. C++ Program to Convert an Integer to a String C++ // C++ Program to Convert an Integer to a String #include <iostream> #include <string> using namespace std; // Driver Code int main() { int num = 42; // converting int to string string str = to_string(num); cout << "Integer to String using to_string(): " << str << endl; return 0; } OutputInteger to String using to_string(): 42 Time Complexity: O(logN)Space Complexity: O(k), where k is the number of digits in the integer N. Create Quiz Comment B bhushanc2003 Follow 0 Improve B bhushanc2003 Follow 0 Improve Article Tags : C++ Programs C++ cpp-strings CPP Examples 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++3 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++12 min readFile Handling in C++8 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++3 min readAbstraction in C++4 min readStandard Template Library(STL)Standard Template Library (STL) in C++3 min readContainers in C++ STL2 min readIterators in C++ STL10 min readC++ STL Algorithm Library3 min readPractice & ProblemsC++ Interview Questions and Answers1 min readC++ Programming Examples4 min read Like