我正在尝试在我的程序中使用boost regex问题是我得到这个错误...我做的唯一安装步骤是将"C:\ Program Files\boost\boost_1_42"添加到其他包含目录中...
我正在使用VS2008 ......
试图实现这个:
#include <iostream>
#include <string>
#include <boost/regex.hpp>
using namespace std;
int main( ) {
std::string s, sre;
boost::regex re;
boost::cmatch matches;
while(true)
{
cout << "Expression: ";
cin >> sre;
if (sre == "quit")
{
break;
}
cout << "String: ";
cin >> s;
try
{
// Assignment and construction initialize the FSM used
// for regexp parsing
re = sre;
}
catch (boost::regex_error& e)
{
cout << sre << " is not a valid regular expression: \""
<< e.what() << "\"" << endl;
continue;
}
// if (boost::regex_match(s.begin(), s.end(), re))
if (boost::regex_match(s.c_str(), matches, re))
{
// matches[0] contains the original string. matches[n]
// contains a sub_match object for each matching
// subexpression
for (int i = 1; i < matches.size(); i++)
{
// sub_match::first and sub_match::second are iterators that
// refer to the first and one past the last chars of the
// matching subexpression
string match(matches[i].first, matches[i].second);
cout << "\tmatches[" << i << "] = " << match << endl;
}
}
else
{
cout << "The regexp \"" << re << "\" does not match \"" << s << "\"" << endl;
}
}
}
Run Code Online (Sandbox Code Playgroud)
什么似乎是问题?应该做任何其他设置?
GMa*_*ckG 14
必须建立一些Boost库; 这是其中之一.以下是构建它们的方法:
创建一个名为的新文件boost_build.bat,并在内部放置:
bjam toolset=msvc-9.0 variant=release threading=multi link=static define=_SECURE_SCL=0 define=_HAS_ITERATOR_DEBUGGING=0
bjam toolset=msvc-9.0 variant=debug threading=multi link=static
Run Code Online (Sandbox Code Playgroud)
注释9.0指的是VS 2008.(2010年为10.0,2005年为8.0,2003年为7.1,6.0为6.0,以及6.0).一旦你完成了这个:
提取build_boost.bat到<boost_root>
转到:
<boost_root>\tools\jam
然后跑build_dist.bat
复制<boost_root>\tools\jam\stage\bin.ntx86\bjam.exe到<boost_root>
跑 boost_build.bat
图书馆位于 <boost_root>\stage\lib
注意,这是我自己的方法.如果有人以更简单的方式说话,或者来自Boost的一些链接,我会很高兴; 似乎很难从Boost找到合适的构建指令.
构建完成后,请确保让编译器知道库在VC目录中的位置(库路径); 添加" <boost_root>\stage\lib".
在bjam定义中,我有_SECURE_SCL=0 _HAS_ITERATOR_DEBUGGING=0发布.这会禁用Release版本中的所有迭代器检查,以提高速度.