0

コード:

#include <string>
#include <boost/regex.hpp>
int main() {
  boost::smatch what;
  boost::regex regex("some +", boost::regex::icase);
  std::string mystring = "some     string";
  bool search_result = boost::regex_search(mystring.begin(),mystring.end(), what, regex);
}

エラーメッセージは長く、最初の行のみがここにあります:

<stdin>: In function 'int main()':
<stdin>:7:88: error: no matching function for call to 'regex_search(std::basic_string<char>::iterator, std::basic_string<char>::iterator, boost::smatch&, boost::regex&)'
<stdin>:7:88: note: candidates are:
In file included from d:\boost/boost/regex/v4/regex.hpp:148:0,
                 from d:\boost/boost/regex.hpp:31,
                 from <stdin>:2:
4

2 に答える 2

3

上記の私のコメントを拡張する

この例では、型の変数を明示的に宣言してから に渡しているためあいまいさはありません。(llonesmiz と同じこと)std::string::const_iteratorboost::regex_search

あるいは、C++11 を使用している場合は、cbeginandを呼び出しcendてあいまいさを取り除くことができます。

于 2013-01-30T16:37:52.940 に答える
1

文字列全体で正規表現を検索しようとしているとのことですが、もしそうなら、これはうまくいくはずです。

#include <string>
#include <boost/regex.hpp>
int main() {
  boost::smatch what;
  boost::regex regex("some +", boost::regex::icase);
  std::string mystring = "some     string";
  bool search_result = boost::regex_search(mystring, what, regex);
}

そして、必要に応じて結果を使用します。

于 2013-01-31T07:29:03.687 に答える