I\'m trying to use safe practices in handling input with numbers only in C++, so I use a stringstream object as so:
#include
#include
A better way to do this conversion between datatypes would be to use boost::lexical_cast
.
Info and examples can be found at the Boost Site.
Below is an example of doing an int to string conversion and back (string to int) such as what you're doing in your program.
#include
#include
int main(int argc, char *argv[])
{
int i = 42;
std::string s = boost::lexical_cast(i);
int j = boost::lexical_cast(s);
return 1;
}