I am trying to learn C++, and have a simple program here (from a tutorial, not mine) that I am trying to compile and run, but the compiler keeps complaining about
"regex.cpp:1:17: error: regex: No such file or directory"
Here is the program:
Initially, it is the first line that is causing all the problems. The compiler can't find <regex>. I even reinstalled boost, but I'm not sure that mattered much.Code:#include <regex> #include <iostream> #include <string> bool is_email_valid(const std::string& email) { // define a regular expression const std::tr1::regex pattern ("(\\w+)(\\.|_)?(\\w*)@(\\w+)(\\.(\\w+))+"); // try to match the string with the regular expression return std::tr1::regex_match(email, pattern); } int main() { std::string email1 = "marius.bancila@domain.com"; std::string email2 = "mariusbancila@domain.com"; std::string email3 = "marius_b@domain.co.uk"; std::string email4 = "marius@domain"; std::cout << email1 << " : " << (is_email_valid(email1) ? "valid" : "invalid") << std::endl; std::cout << email2 << " : " << (is_email_valid(email2) ? "valid" : "invalid") << std::endl; std::cout << email3 << " : " << (is_email_valid(email3) ? "valid" : "invalid") << std::endl; std::cout << email4 << " : " << (is_email_valid(email4) ? "valid" : "invalid") << std::endl; return 0; }
Any ideas? (sorry, but I'm extremely new to this).
Bookmarks