请教使用boost/lexical_cast的问题

yythinking 2005-04-24 05:53:52
想在一个console application中使用boost/lexical_cast将字符串转换为数值的功能,
VC6中设置了include路径,源码如下:

#include "stdafx.h"
#include <iostream>
#include <boost/lexical_cast.hpp>

using namespace std;

int main(int argc, char *argv[])
{
using boost::lexical_cast;
int a = lexical_cast<int>("123");
double b = lexical_cast<double>("123.12");

cout << a << endl;
cout << b << endl;

return 0;
}

编译出错:
error C2062: type 'int' unexpected
error C2062: type 'double' unexpected

请问如何解决?多谢!!!
...全文
129 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
xzgyb 2005-04-25
  • 打赏
  • 举报
回复
vc6对这种在名字空间中的
lexical_cast< int >("123")
似乎支持不太好


#include <iostream>
#include <string>

using namespace std;

namespace gyb
{
template <typename RT>
RT func( void )
{
cout << "hello,gyb" << endl;
return RT();
}
};

int main()
{

// using namespace gyb;
using gyb::func;

func<int>();

return 0;
}

这样就会出现error C2062: type 'int' unexpected的错误
同样的在Devcpp中就通过
而vc中直接using namespace gyb才可以

xzgyb 2005-04-25
  • 打赏
  • 举报
回复
#include <boost/lexical_cast.hpp>
#include <iostream>

using namespace std;
using namespace boost;

int main()
{

int i;
i = lexical_cast< int >("123");

cout << i << endl;

return 0;
}
直接使用
using namespace boost
vc不知道怎么回事
using boost::lexical_cast
使用这种using 声明会有问题
在devcpp中则没问题
allen_zhaozhencn 2005-04-25
  • 打赏
  • 举报
回复
好像没有boost::lexical_cast这个名字空间吧,

直接用boost名称空间名称.
int idata = boost::lexcial_cast<int>("123");


using namspace boost;
int idata = lexcial_cast<int>("123");
antter 2005-04-24
  • 打赏
  • 举报
回复
using namespace std;
using namespace boost;
int main(int argc, char *argv[])
{
int a = lexical_cast<int>("123");
double b = lexical_cast<double>("123.12");

cout << a << endl;
cout << b << endl;

return 0;
}

64,654

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧