C++で新しいstd :: regexを使用する方法を学ぶ11。しかし、私が試した例では、私は理解していないregex_error例外をスローしています。ここに私のサンプルコードは次のとおりです。なぜこのC++ 11 std :: regexの例でregex_error例外がスローされますか?
#include <iostream>
#include <regex>
int main()
{
std::string str = "xyzabc1xyzabc2xyzabc3abc4xyz";
std::regex re("(abc[1234])"); // <-- this line throws a C++ exception
// also tried to do this:
// std::regex re("(abc[1234])", std::regex::optimize | std::regex::extended);
while (true)
{
std::cout << "searching in " << str << std::endl;
std::smatch match;
std::regex_search(str, match, re);
if (match.empty())
{
std::cout << "...no more matches" << std::endl;
break;
}
for (auto x : match)
{
std::cout << "found: " << x << std::endl;
}
str = match.suffix().str();
}
return 0;
}
私はコンパイルして、次のように実行します:gdbの中でバックトレースを見ると
g++ -g -std=c++11 test.cpp
./a.out
terminate called after throwing an instance of 'std::regex_error'
what(): regex_error
、私がスローされた例外がregex_constants::error_brack
ある参照してください。ヒントの
(http://gcc.gnu.org [G ++のlibstdC++のstd ::正規表現をサポートしていません] /onlinedocs/libstdc++/manual/status.html#status.iso.200x) –
あなたが使用しているGCCのバージョンは何? – james82345
@JamesEldridgeも4.8.0は、STDをサポートしていないどのバージョン、問題ではありません::正規表現 – Praetorian