In this C++ tutorial, you shall learn how to convert an integer value to a string value using to_string() function, with example programs.

Convert Integer to String

To convert an integer to a string in C++, we can use std::to_string() method. Pass the given integer value to to_string() method as argument, and the method returns a string value.

The syntax of the expression to convert integer n to string str is

string str = to_string(n);

C++ Program

In the following program, we take an integer value in n, convert this integer to string and store the returned value in str. To use the to_string() method, we shall use namespace std.


#include <iostream>
using namespace std;

int main() {
   int n = 54;
   string str = to_string(n);
   cout << "string value : " << str;


string value : 54


In this C++ Tutorial, we learned how to convert an integer value into a string value using std::to_string() method.