读书人

在VC6中使用boost1.33.1的lexical_cas

发布时间: 2012-03-20 14:01:11 作者: rapoo

在VC6中使用boost1.33.1的lexical_cast编译不能通过的问题
#include <boost/lexical_cast.hpp>
#include <iostream>

void boost_lexical()
{
using boost::lexical_cast;
int a=10;
double b=20;

a = lexical_cast <int> ( "123 ");
b = lexical_cast <double> ( "123.12 ");
std::cout < <a < <std::endl;
std::cout < <b < <std::endl;
}
int main()
{
boost_lexical();
return 0;
}
//////////////////////////////////
Compiling...
main.cpp
F:\000\boost\myboost\main.cpp(15) : error C2062: type 'int ' unexpected
F:\000\boost\myboost\main.cpp(16) : error C2062: type 'double ' unexpected
Error executing cl.exe.

myboost.exe - 2 error(s), 0 warning(s)
////////////////////////////////////////
为什么不能编译通过呢?哪位大大告诉一生?
我的环境:VC6+SP6+WINXPSP2
另:boost的包含路径已经配置好了的


[解决办法]
#include <boost/lexical_cast.hpp>
#include <iostream>
void boost_lexical()
{
using namespace boost;
int a=10;
double b=20;

a = lexical_cast <int> ( "123 ");
b = lexical_cast <double> ( "123.12 ");
std::cout < <a < <std::endl;
std::cout < <b < <std::endl;
}
int main()
{
boost_lexical();
return 0;
}
[解决办法]
写成 a = boost::lexical_cast <int> ( "123 "); 试试
[解决办法]
也有可能你库没有加对路径
[解决办法]
改为:

//using boost::lexical_cast;
int a=10;
double b=20;

a = boost::lexical_cast <int> ( "123 ");
b = boost::lexical_cast <double> ( "123.12 ");


命名空间与模板特化的问题.

读书人网 >C++

热点推荐