Just have a quick question. I\'ve looked around the internet quite a bit and I\'ve found a few solutions but none of them have worked yet. Looking at converting a string to
std::string str = "10";
int number = std::stoi(str);
std::string str = "10";
int number;
std::istringstream(str) >> number
#include
std::string str = "10";
int number;
try
{
number = boost::lexical_cast(str);
std::cout << number << std::endl;
}
catch (boost::bad_lexical_cast const &e) // bad input
{
std::cout << "error" << std::endl;
}
std::string str = "10";
int number = std::atoi(str.c_str());
std::string str = "10";
int number;
if (sscanf(str .c_str(), "%d", &number) == 1)
{
std::cout << number << '\n';
}
else
{
std::cout << "Bad Input";
}