一個BOOST 簡單測試代碼 for linux

[main.cpp]

#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <iostream>
#include <cassert>
#include <boost/lexical_cast.hpp>
#include <boost/regex.hpp>


using namespace std;
using namespace boost;

 

void test1(){
 vector<int> v1;
 vector<int>::const_iterator ci_v1 ;
 int iLength = 0 ;

 while( iLength < 10 )
 {
  try
  {
   if ( iLength == 5 )
    v1.push_back(lexical_cast<int>("DukeJoe")) ;
   else
    v1.push_back(lexical_cast<int>(iLength));
  }
  catch(bad_lexical_cast &ex)
  {
   cout << ex.what()<< endl ;
   v1.push_back(-1);
  }
  iLength++ ;
 }

 cout << "vector --> " ;
 for ( ci_v1 = v1.begin() ; ci_v1 != v1.end() ; ci_v1++ )
 {
  cout << *ci_v1 << " " ;
 }
 cout << endl ;
}

 

int main(int argc, char * argv[])
{

 test1();
 return 0 ;
}

 

[Makefile]

APPLPATH = .
INCLUDE  =  -I$(APPLPATH) -I"/usr/local/include/boost-1_33_1/boost"
BOOST_LIB = -L "/usr/local/lib/"

MAIN_C  =     $(APPLPATH)/main.cpp

CC  = g++
CFLAG  =  -Wall -g -pedantic -ansi

AIM = test

all : $(AIM)

$(AIM) :  main.o
 $(CC)  $(CFLAG) -o  $(AIM)  main.o  $(BOOST_LIB)
 

main.o : $(MAIN_C)
 $(CC) $(INCLUDE)  $(CFLAG) -c $(MAIN_C)


vg :
 valgrind --tool=memcheck --leak-check=full  --show-reachable=yes   -v -q  ./$(AIM) 

clean:
 /rm -rf  *.o   $(AIM)

 

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