
Operator “>” operators can convert int to string in C++.Operator “>”: The “>” operator in the stringstream class is used to read or extract formatted data from a stream object.It includes the following basic methods in the stringstream class: The stringstream class is included in the “sstream” header file. The stringstream class allows input/output operations on streams based on strings. In this section, you will look into all these three methods in detail. There are three different ways in which you can perform conversion of an int to string in C++.

In this article, you will explore how you can convert an integer into a string in C++. In the above example, the first method that uses a string operation to print the current date is more convenient than the second method which uses an arithmetic operation. Today's date is: 31/05/21 Using Arithmetic Operation:Ĭout << "Today's date is: 31/05/" << formattedYear Output:

Using String Operation:Ĭout << "Today's date is: 31/05/" << year.substr(2) Output: For instance, consider the following example to print the current date. Sometimes arithmetic operations become a tedious task compared to string operations. Most of the programming languages provide inbuilt methods to perform explicit type conversion.Ĭonverting data from an integer format to a string allows you to perform various string operations on the data. You can do the conversion of data types in two ways: Implicit type conversion (done by the compiler) and Explicit type conversion (done manually).

There are several cases where you need to convert a variable of one data type to another. Data type conversion is a common process that is widely used in programming.
