Computer Scientist

Tuesday, 10 August 2010

C++ Programming Tips...

Converting from a String to a integer can be achieved by a build-in function atoi() which can be found from the manual page. However the conversion from a integer to a String can not follow the similar method due to the itoa() function  is not a build-in function. It is a compiler dependent method. In C++, there is a handy method:

#include

int number;

std::ostringstream sin;
sin << number;
std::string aString= sin.str();

char* c_type_string = aString.c_str();