• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
一蓑烟雨
C/C++,Linux,语音技术
博客园    首页    新随笔    联系   管理    订阅  订阅
lexical_cast组件
 1 //强制类型转换
 2 #include "stdafx.h"
 3 #include <iostream>
 4 #include <string>
 5 #include <boost/lexical_cast.hpp>
 6 
 7 using namespace std;
 8 
 9 int _tmain(int argc, _TCHAR* argv[])
10 {
11     string str_int="520";  
12     string str_double="520.2314";
13     const double d = 124.45;
14     try
15     {
16         cout << boost::lexical_cast<int>(str_int) << endl;
17         cout << boost::lexical_cast<double>(str_double) << endl;//默认精度为6
18         cout << boost::lexical_cast<string>(d) << endl;
19     }
20     catch(boost::bad_lexical_cast& e)
21     {
22         cerr<<"Bad cast:"<<e.what()<<endl;
23     }
24     return 0;
25 }

 

posted on 2013-01-28 14:44  lovemu  阅读(389)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3