Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

int to string C++ Using stringstream class

#include <iostream>
#include <sstream>
using namespace std;

int main() {
  int num = 05; // a variable of int data type
  
  string str; // a variable of str data type

  // using the stringstream class to insert an int and
  // extract a string
  stringstream a;  
  a << num;  
  a >> str;  

  cout << "The integer value is " << num << endl;  
  cout << "The string representation of the integer is " << str << endl;  
}
Source by softhunt.net #
 
PREVIOUS NEXT
Tagged: #int #string #Using #stringstream #class
ADD COMMENT
Topic
Name
9+9 =