Convert Integer to String C++


Bagus Koko Wibawanto

December 3, 2023

Sometimes we need convert from one data type to anothers. I once get a case where a function parameter use the integer type, but in another function only use string type. The question is how I change from integer to string?. Actually I have experienced the same case but with a different data type. But in this article I wanna discuss how to convert from integer to string. So let's discuss.


Look at the code below.

The code will show the output 20, because fellow integers can perform math operations.


We will use a function in the standar library to convert from integer to string. The function is "to_string()". Let's look at the next code.

We get an error because score variable is not of integer type, but of string type after we use the "to_string()" function. We can't perform math operations with different data type.


That's all guys :)