我正在尝试在我的程序中使用 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;
}
}
}
似乎是什么问题?应该进行任何其他设置吗?