Не могу использовать эту функцию в библиотеке Boost

0

Я работаю над программой, которая использует библиотеку регулярных выражений Boost, и у меня возникает проблема, когда при попытке вызвать функцию boost :: regex_match() у меня возникает странная ошибка, с которой я никогда не сталкивался до. Вот соответствующий код.

boost::regex pattern("REGEX REDACTED");
boost::cmatch what;

XERCES_STD_QUALIFIER cout << "Enter XML Document-Building Commands" << XERCES_STD_QUALIFIER endl;
while(true) {
    // Take the input from the user.
    std::string input;
    XERCES_STD_QUALIFIER cout << ">> ";
    XERCES_STD_QUALIFIER getline(in, input);

    if(boost::regex_match(input, what, pattern)) {
        // whatever
    }
}

Это почти то, что я извлек из примера кода из аналогичной программы, предоставленной моим инструктором для этого задания. Но когда я пытаюсь скомпилировать, я получаю эту ошибку. Если это помогает, я использую NetBeans 8.

XMLDoc.cpp: In member function ‘void XMLDoc::createDoc(std::istream&):
XMLDoc.cpp:164:51: error: no matching function for call to ‘regex_match(std::string&,     boost::cmatch&, boost::regex&)
XMLDoc.cpp:164:51: note: candidates are:
In file included from /usr/include/boost/regex/v4/regex.hpp:145:0,
                 from /usr/include/boost/regex.hpp:31,
                 from XMLDoc.cpp:13:
/usr/include/boost/regex/v4/regex_match.hpp:44:6: note: template<class BidiIterator, class Allocator, class charT, class traits> bool boost::regex_match(BidiIterator, BidiIterator, boost::match_results<Iterator, Allocator>&, const boost::basic_regex<charT, traits>&, boost::regex_constants::match_flag_type)
/usr/include/boost/regex/v4/regex_match.hpp:44:6: note:   template argument deduction/substitution failed:
XMLDoc.cpp:164:51: note:   deduced conflicting types for parameter ‘BidiIterator (‘std::basic_string<char> and ‘boost::match_results<const char*>)
In file included from /usr/include/boost/regex/v4/regex.hpp:145:0,
                 from /usr/include/boost/regex.hpp:31,
                 from XMLDoc.cpp:13:
/usr/include/boost/regex/v4/regex_match.hpp:53:6: note: template<class iterator, class charT, class traits> bool boost::regex_match(iterator, iterator, const boost::basic_regex<charT, traits>&, boost::regex_constants::match_flag_type)
/usr/include/boost/regex/v4/regex_match.hpp:53:6: note:   template argument deduction/substitution failed:
XMLDoc.cpp:164:51: note:   deduced conflicting types for parameter ‘iterator (‘std::basic_string<char> and ‘boost::match_results<const char*>)
In file included from /usr/include/boost/regex/v4/regex.hpp:145:0,
                 from /usr/include/boost/regex.hpp:31,
                 from XMLDoc.cpp:13:
/usr/include/boost/regex/v4/regex_match.hpp:68:13: note: template<class charT, class Allocator, class traits> bool boost::regex_match(const charT*, boost::match_results<const charT*, Allocator>&, const boost::basic_regex<charT, traits2>&, boost::regex_constants::match_flag_type)
/usr/include/boost/regex/v4/regex_match.hpp:68:13: note:   template argument deduction/substitution failed:
XMLDoc.cpp:164:51: note:   mismatched types ‘const charT* and ‘std::basic_string<char>
In file included from /usr/include/boost/regex/v4/regex.hpp:145:0,
                 from /usr/include/boost/regex.hpp:31,
                 from XMLDoc.cpp:13:
/usr/include/boost/regex/v4/regex_match.hpp:77:13: note: bool boost::regex_match(const std::basic_string<charT, ST, SA>&, boost::match_results<typename std::basic_string<charT, ST, SA>::const_iterator, Allocator>&, const boost::basic_regex<charT, traits>&, boost::regex_constants::match_flag_type) [with ST = std::char_traits<char>; SA = std::allocator<char>; Allocator = std::allocator<boost::sub_match<const char*> >; charT = char; traits = boost::regex_traits<char>; typename std::basic_string<charT, ST, SA>::const_iterator = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >; boost::regex_constants::match_flag_type = boost::regex_constants::_match_flags]
/usr/include/boost/regex/v4/regex_match.hpp:77:13: note:   no known conversion for argument 2 from ‘boost::cmatch {aka boost::match_results<const char*>} to ‘boost::match_results<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >, std::allocator<boost::sub_match<const char*> > >&
/usr/include/boost/regex/v4/regex_match.hpp:85:13: note: template<class charT, class traits> bool boost::regex_match(const charT*, const boost::basic_regex<charT, traits>&, boost::regex_constants::match_flag_type)
/usr/include/boost/regex/v4/regex_match.hpp:85:13: note:   template argument deduction/substitution failed:
XMLDoc.cpp:164:51: note:   mismatched types ‘const charT* and ‘std::basic_string<char>
In file included from /usr/include/boost/regex/v4/regex.hpp:145:0,
                 from /usr/include/boost/regex.hpp:31,
                 from XMLDoc.cpp:13:
/usr/include/boost/regex/v4/regex_match.hpp:94:13: note: template<class ST, class SA, class charT, class traits> bool boost::regex_match(const std::basic_string<charT, ST, SA>&, const boost::basic_regex<charT, traits>&, boost::regex_constants::match_flag_type)
/usr/include/boost/regex/v4/regex_match.hpp:94:13: note:   template argument deduction/substitution failed:
XMLDoc.cpp:164:51: note:   ‘boost::cmatch {aka boost::match_results<const char*>} is not derived from ‘const boost::basic_regex<charT, traits>

Может ли кто-нибудь помочь мне здесь? Я уверен, что я правильно включил библиотеку, потому что у меня есть другой проект с теми же свойствами Linker, который использует функцию boost :: regex_match (минус параметр объекта cmatch), и он работает отлично.

Теги:
boost

1 ответ

2
Лучший ответ

Если вы собираетесь использовать ввод std::string, вам нужно использовать boost::smatch вместо boost::cmatch. См. Http://www.boost.org/doc/libs/1_57_0/libs/regex/doc/html/boost_regex/ref/match_results.html. Итак, все, что вам нужно сделать, это изменить

boost::cmatch what;

в

boost::smatch what;
  • 0
    Я также попытался сделать input.c_str () и получил похожую ошибку.
  • 0
    В чем была ошибка? Я могу сделать input.c_str () с boost :: cmatch, и он работает для меня.
Показать ещё 3 комментария

Ещё вопросы

Сообщество Overcoder
Наверх
Меню