सी ++ 11 में नए std :: regex का उपयोग करने का तरीका सीखने की कोशिश कर रहा है। लेकिन मैंने जिस उदाहरण की कोशिश की वह एक regex_error अपवाद फेंक रहा है जिसे मैं समझ नहीं पा रहा हूं।यह सी ++ 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;
}
मैं संकलन और इस तरह चलाएँ:: यहाँ मेरी नमूना कोड है
g++ -g -std=c++11 test.cpp
./a.out
terminate called after throwing an instance of 'std::regex_error'
what(): regex_error
gdb में पश्व-अनुरेखन को देखते हुए, मैं देख रहा हूँ अपवाद उत्पन्न regex_constants::error_brack
है।
(http://gcc.gnu.org [जी ++ libstdC++ std :: regex का समर्थन नहीं करता] /onlinedocs/libstdc++/manual/status.html#status.iso.200x) –
आप किस जीसीसी का उपयोग कर रहे हैं? – james82345
@JamesEldridge कोई फर्क नहीं पड़ता कि संस्करण क्या है, यहां तक कि 4.8.0 std :: regex – Praetorian