Boost 入门之2 - 类型转换

相当于atio,aof.

#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;

#include <boost\lexical_cast.hpp>
using namespace boost;

int _tmain(int argc, _TCHAR* argv[])
{
    int i = 888;
    string str = "999";
    i = boost::lexical_cast<int>(str);
    cout << i << endl;//输出整数:999

    str = "123.123";
    float f = boost::lexical_cast<float>(str);
    cout << f << endl;//输出浮点数: 123.123

    getchar();
    return 0;
}

你可能感兴趣的:(Boost 入门之2 - 类型转换)