boost 系列 1:boost 直接使用
- 在www.boost.org的文档中:
example program (不编译直接使用)
#include <boost/lambda/lambda.hpp>
#include <iostream>
#include <iterator>
#include <algorithm>
int main()
{
using namespace boost::lambda;
typedef std::istream_iterator<int> in;
std::for_each(
in(std::cin), in(), std::cout << (_1 * 3) << " " );
}
2. 配置:
-
From Visual Studio's File menu, select New > Project…
-
In the left-hand pane of the resulting New Project dialog, select Visual C++ > Win32.
-
In the right-hand pane, select Win32 Console Application (VS8.0) or Win32 Console Project (VS7.1).
-
In the name field, enter “example”
-
Right-click example in the Solution Explorer pane and select Properties from the resulting pop-up menu
-
In Configuration Properties > C/C++ > General > Additional Include Directories(关键,添加下列路径到Include文件夹), enter the path to the Boost root directory, for example
C:\Program Files\boost\boost_1_46_1
-
In Configuration Properties > C/C++ > Precompiled Headers, change Use Precompiled Header (/Yu) to Not Using Precompiled Headers.3
-
Replace the contents of the example.cpp generated by the IDE with the example code above.
-
From the Build menu, select Build Solution.
PART 2 Linux
- Linux
参考http://www.boost.org/doc/libs/1_46_1/more/getting_started/unix-variants.html
example program (不编译直接使用)
#include <iostream>
#include <iterator>
#include <algorithm>
int main()
{
using namespace boost::lambda;
typedef std::istream_iterator<int> in;
std::for_each(
in(std::cin), in(), std::cout << (_1 * 3) << " " );
}
编译:
c++ -I path/to/boost_1_46_1 example.cpp -o example
关键是包含boost代码文件夹
然后,同样可以直接运行。