说明
最近想用一下boost,由于习惯Mac系统,所以就打算用Xcode+boost写点代码。首先得安装boost,
安装port或brew,有了它们,安装就简单了,以前我一篇文章介绍了它们的安装与使用。今天我用的是brew, 打开命令行
sudo brew install boost
1.49版本的boost差不多2百多M,安装好后的目录是/usr/local/Cellar/boost/1.49.0
新建一个工程,选择apple command line的工程模板,然后配置头文件与库的目录,分别是:
/usr/local/Cellar/boost/1.49.0/include
/usr/local/Cellar/boost/1.49.0/lib
测试
写一个hello word, 用到了boost的作用域指针。参看:http://zh.highscore.de/cpp/boost/
#include <iostream>
#include <boost/scoped_ptr.hpp>
int main(int argc, const char * argv[])
{
// insert code here...
std::cout << "Hello, World!\n";
boost::scoped_ptr<int> i(new int);
*i = 1;
*i.get() = 2;
i.reset(new int);
return 0;
}