用google 搜一下, 發現關於 c++ boost 庫沒有繁體中文資源, 所以把手記寫在blog上, 讓有緣人也可以看一下.
http://www.boost.org/libs/conversion/lexical_cast.htm
int main(int argc, char * argv[])
{
using boost::lexical_cast;
using boost::bad_lexical_cast;
std::vector<short> args;
while(*++argv)
{
try
{
args.push_back(lexical_cast<short>(*argv));
}
catch(bad_lexical_cast &)
{
args.push_back(0);
}
}
...
}
有一天我打了一百多個gcvt 跟itoa , 就開始後悔沒有早點碰到 boost 庫.
#include <boost/lexical_cast.hpp> #include <string> #include <iostream> int main() { using std::string; const double d = 123.12; string s = boost::lexical_cast<string>(d); std::cout<<s<<std::endl; return 0; }看吧, 超好用!~
呵,找 boost::lexical_cast 的資料找到了這裡。感謝提供資訊。
回覆刪除路過的有緣人 ^_^