Hi, I'm having trouble when I'm trying to run regular expression code. It compiled fine but when I run it in CodeBlocks I'm getting this error
terminate called after throwing an instance of 'std::regex_error'
what(): regex_error
Aborted (core dumped)
Here is the code (taken from http://www.cplusplus.com/reference/)
As you can see it work fine on cpp.sh. And yes I did enable C++11 support. Anyone know what the problem might be?
#include <iostream>
#include <string>
#include <regex>
int main ()
{
std::string s ("this subject has a submarine as a subsequence");
std::smatch m;
std::regex e ("\\b(sub)([^ ]*)"); // matches words beginning by "sub"
std::cout << "Target sequence: " << s << std::endl;
std::cout << "Regular expression: /\\b(sub)([^ ]*)/" << std::endl;
std::cout << "The following matches and submatches were found:" << std::endl;
while (std::regex_search (s,m,e)) {
for (auto x:m) std::cout << x << " ";
std::cout << std::endl;
s = m.suffix().str();
}
return 0;
}
The IDE isn't what's limiting you, just the compiler, CodeBlocks is a good IDE imo. I would suggest installing your own, up-to-date compiler to work with CodeBlocks, it shouldn't be too hard. http://wiki.codeblocks.org/index.php?title=Installing_a_supported_compiler#Linux should help, although I haven't used CodeBlocks on Linux only g++ itself.
(Also, not sure how outdated that wiki article is, I'm petty sure you can get clang support as well, but I don't know).
Tnx a lot for answers guys! I tryed to compile the same code fragment using by just creating empty .cpp file and putting same code within it, than compiled it with
g++ -std=c++11 -o exmpl example.cpp
and I got the same error message. So at least now i know that its actually compiler not CodeBlocks thats causing it. Tnx :)