Boost

来自开放百科 - 灰狐
(版本间的差异)
跳转到: 导航, 搜索
第28行: 第28行:
 
  int main()
 
  int main()
 
  {
 
  {
using boost::lexical_cast;         
+
  using boost::lexical_cast;         
int a = lexical_cast<int>("123");
+
  int a = lexical_cast<int>("123");
double b = lexical_cast<double>("123.12");
+
  double b = lexical_cast<double>("123.12");
std::cout<<a<<std::endl
+
  std::cout<<a<<std::endl;
std::cout<<b<<std::endl;
+
  std::cout<<b<<std::endl;
return 0;
+
  return 0;
 
  }
 
  }
 +
g++ -o test -I/usr/local/include/boost-1_33_1/ test.cpp
 +
./test
 +
123
 +
123.12
 
==Links==
 
==Links==
 
*http://www.boost.org/
 
*http://www.boost.org/

2007年2月11日 (日) 14:27的版本

“...one of the most highly regarded and expertly designed C++ library projects in the world.” — Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

Build and Install

wget http://jaist.dl.sourceforge.net/sourceforge/boost/boost_1_33_1.tar.gz
tar zxvf boost_1_33_1.tar.gz
cd boost_1_33_1
#apt-get install bjam // bjam: Software build tool
#bjam "-sTOOLS=gcc" install // long time , install to /usr/local/lib
or 
./configure CPPFLAGS="-Iboost_1_33_1" LDFLAGS="-Lboost_1_33_1/libs"
make 
make install 

Debian:

apt-get install libboost-date-time-dev
apt-get install libboost-filesystem-dev
apt-get install libboost-regex-dev
apt-get install libboost-serialization-dev
apt-get install libboost-test-dev
apt-get install libboost-dev

on fedora:

apt-get install boost-devel 
apt-get install g++ 

Examples

#include <boost/lexical_cast.hpp>
#include <iostream>
int main()
{
 using boost::lexical_cast;        
 int a = lexical_cast<int>("123");
 double b = lexical_cast<double>("123.12");
 std::cout<<a<<std::endl;
 std::cout<<b<<std::endl;
 return 0;
}
g++ -o test -I/usr/local/include/boost-1_33_1/ test.cpp
./test
123
123.12

Links

分享您的观点
个人工具
名字空间

变换
操作
导航
工具箱