You can convert a string to a number using the following function:
#include <sstream>
#include <string>
#include <ios>
template<class T>
bool str2num( const std::string& s, T *pNumber,
std::ios_base::fmtflags fmtfl = std::ios_base::dec )
{
std::istringstream stm( s.c_str() );
stm.flags( fmtfl );
stm >> (*pNumber);
return stm.fail() == false;
}
To convert to an integer call as follows:
int output;
bool success = str2num( iterations, &output );
source
share