How to convert an integer into String?

stalin s - May 1 '21 - - Dev Community

IN order to convert an integer into a string

we are supposed to use an object of the input/output class.

-----> Stringstream ---> (String stream)
-----> iStringstream --> (input string stream)
------> oStringstream ---> (output string stream)

The above functions are defined in the header files.

"stream".

Steps to convert an integer into a string.

step 1: include header files #:include".
step 2: Take a Integral data.
Step 3: Declare the output string stream.
Step 4: Sending the integer as a stream the output string stream.
Step 5: Finally declare a string variable where you want to store the new string.

code :

include

include

using namespace std;
int main()
{

int n = 2344;
//declare output string stream
ostringstream strq;

//sending integer as a stream into a string stream

strq<<n;

//declare string variable

string s = strq.str();
// output the string

cout<<"output the converted string is"<<s<<endl;

return 0;

}

Thank you:)

. . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player