Posts

Showing posts with the label Int to string

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

Image
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; }