boost的安装与调试

boost是一个开源的c++库,离c++标准只有一步之 遥的库.昨天重装了boost,于是就有了这篇文章.

cd n:/programme
//下载boost
N:/programme>cvs -d:pserver:anonymous@boost.cvs.sourceforge.net:/cvsroot/boost login
N:/programme>cvs -z3 -d:pserver:anonymous@boost.cvs.sourceforge.net:/cvsroot/boost co -P boost
//编译bjam
N:/programme>cd boost/tools/jam
N:/programme/boost/tools/jam>build_dist
...
N:/programme/boost/tools/jam>cd src/bin.ntx86
N:/programme/boost/tools/jam/src/bin.ntx86>dir/b
bjam.exe

N:/programme/boost/tools/jam/src/bin.ntx86>copy b* n:/programme/boost
N:/programme/boost/tools/jam/src/bin.ntx86>cd n:/programme/boost
//按不同编译器修改-sTools=后面的值具体参见文档,--prefix是安装的目标位置,默认是c:/boost或/usr/local
N:/programme/boost>bjam "-sTOOLS=vc-8_0" --prefix=n:/programme/libs/boost
//不晓得编了多少时间,诂计2个多钟头吧
N:/programme/boost>cd ../libs/boost
//编译成功
N:/programme/libs/boost>dir /b
include
lib

N:/programme/libs/boost>
把include,和lib路径加入vs

随便写个测试代码检测一下是否安装成功

 

#include <boost/lexical_cast.hpp>
#include 
<boost/bind.hpp>
#include 
<boost/smart_ptr.hpp>
#include 
<string>
#include 
<vector>
#include 
<iostream>
#include 
<ctime>
#include 
<iterator>
#include 
<algorithm>
using namespace  std;
using namespace
 boost;

template
<typename T>

class myvec:public vector<T>
 {
 
public :
  myvec(
void
)
   {
   cout
<<this<<" created."<<
endl;
   }
  
~myvec(void
)
   {
   cout
<<this<<" destroyed."<<
endl;
   }
  
void push_back(const T&
 str)
   {
   vector
<T>
::push_back(str);
   cout
<<this<<" push_back "<<str<<
endl;
   }
  
void show(void
)
   {
   copy(begin(),end(),ostream_iterator
<T>(cout," "
));
   cout
<<
flush;
   }
 };
typedef myvec
<string>
 vec_string;
bool myless(const string& left,const string&
 right)
 {
 
return atoi(left.c_str())<
atoi(right.c_str());
 }

int main(int argc,char**
 argv)
 {
 srand((unsigned 
int
)time(NULL));
 shared_ptr
<vec_string> ptr(new vec_string); //shared_ptr引用计数+1 类似COM的AddRef

 for(int i=0;i<10;i++ )
  {
  ptr
->push_back(lexical_cast<string>(rand()%10000)); //兜了个圈子,这里int转成string,一会比较时还要atoi

  }
 cout
<<"sorting"<<
endl;
 sort(ptr
->begin(),ptr->end(),boost::bind(myless,_1,_2));//bind

 ptr-> show();
 
return 0
;
 }
//shared_ptr引用计数-1,且为0,vec_string从内存中delete


//输出
003A57B8 created.
003A57B8 push_back 6959
003A57B8 push_back 6874
003A57B8 push_back 2690
003A57B8 push_back 3038
003A57B8 push_back 32
003A57B8 push_back 3205
003A57B8 push_back 471
003A57B8 push_back 9282
003A57B8 push_back 61
003A57B8 push_back 890
sorting
32
61
471
890
2690
3038
3205
6874
6959
9282
003A57B8 destroyed.

测试是成功的.

我的Blog是: http://blog.csdn.net/antter
Email: jmiwork@yahoo.com
QQ: 185500511

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值