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:)
Top comments (2)
bad writing
Thanks for rectifying my mistake π will throw proper content .π