Boost (1.34) 正则表达式语法错误
我已经阅读了一些文档,并且对 VS2010 附带的当前版本更加熟悉。但现在我被困在 ubuntu 8.04 和 boost 1.34 中,并且遇到了一些奇怪的错误。谁能告诉我我做错了什么。这是 regex_search boost v1.34
这是我在代码中所做的:
std::string sLine;
getline(dataFile, sLine);
boost::match_results<std::string::const_iterator> lineSmatch;
boost::match_flag_type regFlags = boost::match_default;
boost::regex finalRegex(linePattern);
boost::regex_search(sLine.begin(), sLine.end(), lineSmatch, finalRegex, regFlags);
这是编译错误:
错误:没有匹配的函数用于调用 'regex_search(__gnu_cxx::__normal_iterator, std::allocator > >, __gnu_cxx::__normal_iterator, std: : 分配器 >, boost::match_results<__gnu_cxx::__normal_iterator, std:: 分配器 >, std::分配器 > > :regex&, boost::regex_constants::match_flag_type&)'
I have read some amount of documentation, and I am more familiar with the current version being shipped with VS2010. But for now I am stuck with ubuntu 8.04, and boost 1.34 and am getting some weird sort of error. Can anybody tell what I am doing wrong. Here is the man page for regex_search boost v1.34
Here is what I am doing in my code :
std::string sLine;
getline(dataFile, sLine);
boost::match_results<std::string::const_iterator> lineSmatch;
boost::match_flag_type regFlags = boost::match_default;
boost::regex finalRegex(linePattern);
boost::regex_search(sLine.begin(), sLine.end(), lineSmatch, finalRegex, regFlags);
Here is the compilation error:
error: no matching function for call to 'regex_search(__gnu_cxx::__normal_iterator, std::allocator > >, __gnu_cxx::__normal_iterator, std::allocator > >, boost::match_results<__gnu_cxx::__normal_iterator, std::allocator > >, std::allocator, std::allocator > > > > >&, boost::regex&, boost::regex_constants::match_flag_type&)'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您要将
regex_search
应用到sLine
本身而不是iterator
范围,正如Howard回答的那样,您可以使用sLine
代替begin()
和end()
。例如:
如果您必须将
iterator
范围指定给regex_search
,因为类型match_results
的参数是const_iterator
,第一个和第二个regex_search
的参数也需要是const_iterator
。例如:
希望这有帮助
If you are going to apply
regex_search
tosLine
itself instead ofiterator
range, as Howard answered, you can usesLine
instead ofbegin()
andend()
.For example:
If you have to give
iterator
range toregex_search
, since the typeargument for
match_results
isconst_iterator
, the first and secondarguments for
regex_search
need to beconst_iterator
too.For example:
Hope this helps
无法帮助您具体了解 ubuntu 8.04 和 boost 1.34。然而,以下内容在实现 C++11 的 libc++ 上为我编译。也许它与您的环境足够接近,可以告诉您出了什么问题。
Can't help you specifically with ubuntu 8.04, and boost 1.34. However the following compiles for me on libc++ which implements C++11. Perhaps it is close enough to your environment to tell you what is wrong.