Converting from a std::string to bool
I am surprised that no one mentioned this one:
bool b;
istringstream("1") >> b;
or
bool b;
istringstream("true") >> std::boolalpha >> b;
bool to_bool(std::string const& s) {
return s != "0";
}
It'll probably be overkill for you, but I'd use boost::lexical_cast
boost::lexical_cast<bool>("1") // returns true
boost::lexical_cast<bool>("0") // returns false