Boost (1.34) 正则表达式语法错误

发布于 2024-10-28 01:05:33 字数 893 浏览 6 评论 0原文

我已经阅读了一些文档,并且对 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风吹短裙飘 2024-11-04 01:05:33

如果您要将 regex_search 应用到 sLine 本身而不是
iterator范围,正如Howard回答的那样,您可以使用sLine代替
begin()end()
例如:

boost::regex_search(sLine, lineSmatch, finalRegex, regFlags);

如果您必须将 iterator 范围指定给 regex_search,因为类型
match_results 的参数是 const_iterator,第一个和第二个
regex_search 的参数也需要是 const_iterator
例如:

std::string::const_iterator b = sLine.begin(), e = sLine.end();
boost::regex_search(b, e, lineSmatch, finalRegex, regFlags);

希望这有帮助

If you are going to apply regex_search to sLine itself instead of
iterator range, as Howard answered, you can use sLine instead of
begin() and end().
For example:

boost::regex_search(sLine, lineSmatch, finalRegex, regFlags);

If you have to give iterator range to regex_search, since the type
argument for match_results is const_iterator, the first and second
arguments for regex_search need to be const_iterator too.
For example:

std::string::const_iterator b = sLine.begin(), e = sLine.end();
boost::regex_search(b, e, lineSmatch, finalRegex, regFlags);

Hope this helps

生寂 2024-11-04 01:05:33

无法帮助您具体了解 ubuntu 8.04 和 boost 1.34。然而,以下内容在实现 C++11 的 libc++ 上为我编译。也许它与您的环境足够接近,可以告诉您出了什么问题。

#include <regex>
#include <fstream>

int main()
{
    std::ifstream dataFile;
    std::string sLine, linePattern;
    getline(dataFile, sLine);
    std::match_results<std::string::const_iterator> lineSmatch; 
    std::regex_constants::match_flag_type regFlags = 
                                        std::regex_constants::match_default;    
    std::regex finalRegex(linePattern);

    std::regex_search(sLine, lineSmatch, finalRegex, regFlags);
}

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.

#include <regex>
#include <fstream>

int main()
{
    std::ifstream dataFile;
    std::string sLine, linePattern;
    getline(dataFile, sLine);
    std::match_results<std::string::const_iterator> lineSmatch; 
    std::regex_constants::match_flag_type regFlags = 
                                        std::regex_constants::match_default;    
    std::regex finalRegex(linePattern);

    std::regex_search(sLine, lineSmatch, finalRegex, regFlags);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文