String to Int Conversion in C++

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++



Share on Google Plus

About Asad

Asad Niazi is Software Engineer , Programmer, Web Developer and a young mentor of BloggersTown and PProgramming. Asad Love to writes about Technology, Programming, Blogging and make money online.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment