Showing posts with label How to convert a String into integers conversion in C. Show all posts
Showing posts with label How to convert a String into integers conversion in C. Show all posts

Thursday, 5 February 2015

String to int conversion in C++

Structure of the Problem Requirements 

String stream class is used to convert a string into integers, just make a object of string stream class and pass the string which you want to convert into integer. >> Operates is used to read something or some value from the string stream object.

Source Code

#include <iostream>
#include <sstream>
int main()
{
using namespace std;
cout<<"\t \t \t LEP Tutorials \n \n ";
string str = "786";
cout << " Store in String : "<<str <<endl<< endl;
stringstream ss(str);
int a;
ss >> a;
cout << " Store in int : "<<a << endl;
return 0;
}

Output of the Program

String to int conversion in C++