Convert Integer To String And String To integer in c++

Convert Integer  To String in c++




# Code 

#include<iostream>
#include<sstream> // include this header file to convert
using namespace std;
int main()
{
    int i = 5432;
 
// declare output stream
ostringstream stm; 
//passing intger variable as stream to output stream
stm<<i;
// get string output using str()
string s = stm.str();
cout<<"string is : "<<s; 
    cout<<"\n 1st index : "<<s[0];
    cout<<"\n 3rd index : "<<s[3];
return 0;
}

# code To String to integer

#include<iostream>
#include<sstream>
using namespace std;
int main()
{
string s = "1234";
stringstream ss(s);
int i ;
ss>>i;
 
cout<<" integer : "<<i;
}


 

Comments

Popular posts from this blog

Remote Method Invokation (RMI) in Java

Changing the Title of Website on Button Click in React Hook tut 14

useContext() in React tut 12