std::istringstream s(str);
s >> i;

または

i = atoi(str.str());

または

i = boost::lexical_cast<int>(str);