- #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) << " " );
- }
前面已经简单的使用了boost库,但是如果想要使用
- Boost.Filesystem
- Boost.GraphParallel
- Boost.IOStreams
- Boost.MPI
- Boost.ProgramOptions
- Boost.Python (see the Boost.Python build documentation before building and installing it)
- Boost.Regex
- Boost.Serialization
- Boost.Signals
- Boost.System
- Boost.Thread
- Boost.Wave
等,还是的编译一下,要不然就会出现如下的错误“LINK : fatal error LNK1104: 无法打开文件“libboost_regex-vc100-mt-gd-1_46_1.lib”
打开命令行窗口
切换到 boost库的根目录。
我的是E:/mylib/boost_1_46_1
输入bootstrap
然后有几行输出
再输入./bjam
类库编译开始(这个真是个漫长的过程 ………………)
哎 等了 1个小时了
还得等
再编译一会儿吧
N久之后 编译好了
ln-NT stage/lib/libboost_unit_test_framework-vc100-mt.lib
"NT symlinks not supported yet, making copy"
已复制 1 个文件。
ln-NT stage/lib/libboost_thread-vc100-mt.lib
"NT symlinks not supported yet, making copy"
已复制 1 个文件。
ln-NT stage/lib/libboost_wave-vc100-mt.lib
"NT symlinks not supported yet, making copy"
已复制 1 个文件。
...updated 786 targets...
The Boost C++ Libraries were successfully built!
The following directory should be added to compiler include paths:
E:/mylib/boost_1_46_1
The following directory should be added to linker library paths:
E:/mylib/boost_1_46_1/stage/lib
用如下代码替换上一次的那个example.cpp的内容
- #include <boost/regex.hpp>
- #include <iostream>
- #include <string>
- int main()
- {
- std::string line;
- boost::regex pat( "^Subject: (Re: |Aw: )*(.*)" );
- while (std::cin)
- {
- std::getline(std::cin, line);
- boost::smatch matches;
- if (boost::regex_match(line, matches, pat))
- std::cout << matches[2] << std::endl;
- }
- }
在工程中添加库引用
属性>连接器>常规 > 附加目录库 这里写入 E:/mylib/boost_1_46_1/stage/lib
编译
运行
输入
To: George Shmidlap From: Rita Marlowe Subject: Will Success Spoil Rock Hunter?
输出
Will Success Spoil Rock Hunter?
一个简单的正则表达式编译成功。
至此,boost库编译成功。
- In Configuration Properties > Linker > Additional Library Directories, enter the path to the Boost binaries, e.g. C:/Program Files/boost/boost_1_46_1/lib/.
- From the Build menu, select Build Solution.