我在网上找了一个别人已经编译好的boost
打开vs2013 ,新建一个c++控制台工程:
#include "stdafx.h"
#include <boost/lexical_cast.hpp>
#include <string>
#include <iostream>
using namespace std;
using boost::lexical_cast;
int main()
{
int a = lexical_cast<int>("123");
double b = lexical_cast<double>("4.6987");
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;
}
system("pause");
return 0;
}
编译后的结果如下:
FR:hunk xu