【Boost】系列05:数值与字符串转换

#include <boost/lexical_cast.hpp>

#include <iostream>

using namespace boost;

using namespace std;



int main()

{

    int x = lexical_cast<int>("100");

    long y = lexical_cast<long>("2000"); 

    float pi = lexical_cast<float>("3.14159e5");

    double e = lexical_cast<double>("2.71828");



    cout<<"x="<<x<<"  y="<<y<<"  pi="<<pi<<"  e="<<e<<endl;



    string str = lexical_cast<string>(456);

    cout<<str<<endl;

    cout<<lexical_cast<string>(0.618)<<endl;

    cout<<lexical_cast<string>(0x10)<<endl;



    return 0;



}

输出:

x=100  y=2000  pi=314159  e=2.71828

456

0.61799999999999999

16

你可能感兴趣的:(boost)