读书人

基于boost:lexical_cast的to_string函

发布时间: 2012-09-13 09:51:53 作者: rapoo

基于boost::lexical_cast的to_string函数

#include <iostream>#include <string>#include "boost/lexical_cast.hpp"template <typename T> std::string to_string(const T& arg) {try {return boost::lexical_cast<std::string>(arg);}catch(boost::bad_lexical_cast& e) {return "";}}int main() {std::string s = to_string(412);std::cout << s << std::endl;s = to_string(2.357);std::cout << s << std::endl;}

读书人网 >操作系统

热点推荐