View Single Post
Old 03-02-2003, 12:45 AM   #4 (permalink)
Neophyte
Registered User
 
Neophyte's Avatar
 
Join Date: Mar 2003
Posts: 1
Neophyte is on a distinguished road
If you're using C++, you can do it like this:

Code:
#include <string>
#include <sstream>
#include <iostream>
using namespace std;

int main(void) {
  string str = "12345";
  int num;
  string conv;

  /* convert str to int */
  istringstream iss ( str );
  iss >> num;
  cout << "num: " << num << endl;

  /* convert num to string */
  ostringstream oss;
  oss << num;
  istringstream iss2 ( oss.str() );
  iss2 >> conv;
  cout << "conv: " << conv << endl;

}
Neophyte is offline   Reply With Quote