boost linux 测试程序,Linux Boost 安装, 测试程序

下载:

wget http://101.96.10.75/ncu.dl.sourceforge.net/project/boost/boost/1.62.0/boost_1_62_0.tar.bz2

tar xf boost_1_62_0.tar.bz2

cd boost_1_62_0/

编译安装

bash bootstrap.sh

echo $?

./b2

echo $?

sudo ./b2 install --prefix=/tmp/haha  #/tmp/haha是我建立的目录

echo $?

chunli@linux:~$ ll /tmp/haha/

total 8.0K

drwxr-xr-x 3 root root 4.0K Oct 18 20:58 include

drwxr-xr-x 2 root root 4.0K Oct 18 20:59 lib

chunli@linux:~$ du -sh /tmp/haha/

184M/tmp/haha/

chunli@linux:~$

写个测试程序:

root@linux:/tmp# cat main.cpp

#include 

#include 

using namespace std;

int main()

{

using boost::lexical_cast;

int a=lexical_cast("123");

double b=lexical_cast("123.0123456789");

string s0=lexical_cast(a);

string s1=lexical_cast(b);

cout<

cout<

int c=0;

try{

c=lexical_cast("abcd");

}

catch(boost::bad_lexical_cast& e){

cout<

}

cout <

return 0;

}

root@linux:/tmp# g++ main.cpp && ./a.out

number: 123  123.012

string: 123  123.0123456789

bad lexical cast: source type value could not be interpreted as target

Hello

root@linux:/tmp#

编译报错:

chunli@ubuntu14:/tmp$ g++ main.cpp

main.cpp:1:39: fatal error: boost/lexical_cast.hpp: No such file or directory

#include 

^

compilation terminated.

解决办法:指定头文件

chunli@ubuntu14:/tmp$ g++ main.cpp -I haha/include/

chunli@ubuntu14:/tmp$ ./a.out

number: 123  123.012

string: 123  123.0123456789

bad lexical cast: source type value could not be interpreted as target

Hello

chunli@ubuntu14:/tmp$

永久的解决办法,放到系统的路径下

chunli@ubuntu14:/tmp$ sudo mv haha/include/* /usr/include/

chunli@ubuntu14:/tmp$ sudo mv haha/lib/ /usr/lib/

chunli@ubuntu14:/tmp$ g++ main.cpp  && ./a.out

number: 123  123.012

string: 123  123.0123456789

bad lexical cast: source type value could not be interpreted as target

Hello

chunli@ubuntu14:/tmp$

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值