DEV Community

Cover image for How to convert an integer into String?
stalin s
stalin s

Posted on • Edited on

How to convert an integer into String?

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:)

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (2)

Collapse
 
muhyilmaz profile image
MUHAMMED YILMAZ

bad writing

Collapse
 
stali1234 profile image
stalin s

Thanks for rectifying my mistake 👍 will throw proper content .👍

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay