当前位置:天才代写 > tutorial > C语言/C++ 教程 > 实战准尺度库Boost(2)测试Boost设置的Hello World措施

实战准尺度库Boost(2)测试Boost设置的Hello World措施

2017-11-03 08:00 星期五 所属: C语言/C++ 教程 浏览:451

1. 设置情况

请先凭据《Boost C++ Libs —— (1)设置Boost的VS2008开拓情况》一文在Visual Studio中设置开拓情况。

2. 源码

#include <boost/lexical_cast.hpp>       
#include <iostream>       

using namespace std;     

int main()
{
    using boost::lexical_cast;

    int a=lexical_cast<int>("123");
    double b=lexical_cast<double>("123.0123456789");
    string s0=lexical_cast<string>(a);
    string s1=lexical_cast<string>(b);
    cout<<"number: "<<a<<"  "<<b<<endl;
    cout<<"string: "<<s0<<"  "<<s1<<endl;
    int c=0;
    try{
        c=lexical_cast<int>("abcd");
    }
    catch(boost::bad_lexical_cast& e){       
        cout<<e.what()<<endl;
    }

    return 0;      
}

 

    关键字:

[contact-form-7 id="17097" title="form2"]天才代写-代写联系方式