g++ boost庫編譯及測試

1.downlaod boost.zip

2.unzip xx.zip

3.upload to linux

4.chmod a+x bootstrap.sh

5../bootstrap.sh 如出現其他權限不夠情況,請依次更改

6.wait for some secondes

7.copy boost/boost to /usr/include/boost

8.copy boost/stages/libs to /usr/local/lib/boost

9.upload cpp,編譯

g++ -o boost xx.cpp

10.運行:

./boost


cpp 如下:

// testBoost.cpp : 定義控制檯應用程序的入口點。
//

//#include "stdafx.h"

#include <stdio.h>

//#include <boost/pool/pool.hpp>
//#include <boost/pool/object_pool.hpp>
//#include <boost/container/vector.hpp>
//#include <boost/ptr_container/ptr_vector.hpp>
//#include <boost/container/string.hpp>
//#include <boost/container/deque.hpp>
//#include <boost/container/stable_vector.hpp>
//#include <boost/container/map.hpp>
#include <boost/container/list.hpp>
//#include <boost/container/set.hpp>
//
using namespace boost;
using namespace boost::container;

//#define CRTDBG_MAP_ALLOC 
//#include <stdlib.h>
//#include <crtdbg.h>

struct MyMem
{
public:
	MyMem()
	{
		a = 0;
		b = 0;
	}

	void Set(int a,char b)
	{
		this->a = a;
		this->b = b;
	}

	void Init()
	{
		a = 0;
		b = 0;
	}
	void print()
	{
		printf("%d,%d\n",a,b);
	}
private:
	int a;
	char b;
};

typedef object_pool<MyMem> _pool;

int _tmain(int argc, _TCHAR* argv[])
{
	////c
	//MyMem * p2 = (MyMem*)malloc(sizeof(MyMem)+1);

	//p2->Init();

	//p2->print();

	//free(p2);

	////c++
	//MyMem * p1 = new MyMem();

	//p1->print();

	//delete p1;
	//p1 = NULL;

	////pool

	//pool<> _basePool(sizeof(MyMem));

	//MyMem * p = (MyMem*)_basePool.malloc();

	//p = new(p)MyMem();

	//p->print();

	//_basePool.free(p);

	////object_pool

	//_pool mypool;

	//void * obj = mypool.malloc();

	//MyMem* myMem = new(obj)MyMem();

	//myMem->print();

	//mypool.free(myMem);

	////
	////_CrtDumpMemoryLeaks();
	

	//vector

	//vector<MyMem> _v1;

	//for (int i=0;i<3;i++)
	//{
	//	MyMem tmp;
	//	tmp.Set(i+10,i);
	//	_v1.push_back(tmp);
	//}

	//for (int i=0;i<4;i++)
	//{
	//	_v1[i].print();
	//}

	//for (int i=0;i<3;i++)
	//{
	//	MyMem tmp;
	//	tmp.Set(i+10,i);
	//	//_v1.insert(_v1.begin(),tmp);
	//	//_v1.insert(_v1.end()-1,tmp);
	//}

	//for (vector<MyMem>::iterator it = _v1.begin();it!=_v1.end();++it)
	//{
	//	it->print();
	//}

	//vector<MyMem*> _v2;
	//for (int i=0;i<3;i++)
	//{
	//	MyMem * p = new MyMem();
	//	p->Set(i+10,i);
	//	_v2.push_back(p);
	//}

	//for (vector<MyMem*>::iterator it = _v2.begin();it!=_v2.end();++it)
	//{
	//	((MyMem*)(*it))->print();
	//}

	//ptr_vector

	//ptr_vector<MyMem> _v3;
	////MyMem * p = new MyMem();
	////p->Set(10,1);
	//_v3.push_back(new MyMem());
	//_v3[0].print();

	//string

	//string x = "123";
	//printf(x.c_str());

	//deque
	
	//deque<MyMem> _v4;
	//for (int i=0;i<3;i++)
	//{
	//	MyMem p;
	//	p.Set(i+10,i);
	//	_v4.push_back(p);
	//}

	////for (int i=0;i<3;i++)
	////{
	////	_v4[i].print();
	////}

	//_v4.pop_back();

	//for (deque<MyMem>::iterator it = _v4.begin();it!=_v4.end();++it)
	//{
	//	it->print();
	//}

	//stable_vector

	//stable_vector<MyMem> _v5;

	//MyMem p;
	//_v5.push_back(p);
	//_v5[0].print();

	////map
	//
	//map<int,MyMem> _v6;
	//MyMem p;
	//p.Set(10,1);
	//_v6.insert(map<int,MyMem>::value_type(1,p));
	//for (int i=0;i<3;i++)
	//{
	//	_v6[i];//.print();
	//}
	//printf("map size=%d\n",_v6.size());

	//warning:map ptr is not fix [] operator

	//map<int,MyMem*> _v7;
	//MyMem * p = new MyMem();
	//p->Set(10,1);
	//_v7.insert(map<int,MyMem*>::value_type(1,p));
	//for (int i=0;i<3;i++)
	//{
	//	_v7[i]->print();
	//}
	//printf("map size=%d\n",_v7.size());

	//list

	list<MyMem> _v8;
	_v8.push_back(MyMem());
	MyMem x = _v8.front();
	x.print();
	
	printf("123\n");

	getchar();

	return 0;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章