提示:
#include <iostream> #include <boost/lexical_cast.hpp> using namespace std; using namespace boost; int main() { string s = "123"; int a = lexical_cast<int>(s); double b = lexical_cast<double>(s); printf("%d/r/n", a + 1); printf("%lf/r/n", b + 1); try { //为了防止转化错误使用一个错误的例子 int c = lexical_cast<int>("wrong_number"); } catch(bad_lexical_cast & e) { printf("%s/r/n", e.what()); } return 0; }
boost::lexical_cast常见用法详解之万能转换
原文地址:http://blog.csdn.net/qingzai_/article/details/44415787