简体   繁体   中英

‘multiline’ is not a member of ‘std::__cxx11::regex’

I am trying to compile the following C++ code using the command:

g++ -std=c++17 -o rgx rgx.cpp

#include <iostream>
#include <regex>
#include <string>
using namespace std;

int main() {
        regex rgx("^([A-Z]*)$", regex::ECMAScript | regex::multiline | regex::icase);
        smatch rmtch;
        string str = "AbcefgH\r\nTest";
        if (regex_match(str, rmtch, rgx)) {
                for (size_t i = 0; i < rmtch.size(); i++) {
                        ssub_match smtch = rmtch[i];
                        string s_m = smtch.str();
                        cout << " submatch " << i << ": " << s_m << endl;
                }
        }
        return 0;
};

However get the following compile time error

rgx.cpp: In function ‘int main()’:
rgx.cpp:7:53: error: ‘multiline’ is not a member of ‘std::__cxx11::regex’ {aka ‘std::__cxx11::basic_regex<char>’}
    7 |  regex rgx("^([A-Z]*)$", regex::ECMAScript | regex::multiline | regex::icase);
g++ --version
g++ (Ubuntu 9.1.0-8ubuntu1) 9.1.0

Why is g++ using __cxx11::regex when I've specified -std=c++17?

cppreference.com/w/cpp/regex/basic_regex defines regex::multiline as being part of the C++17 standard

Libstdc++ doesn't appear to implement regex::multiline .

Note that the fact that it's using std::__cxx11::regex doesn't mean that you're stuck in the past. __cxx11 is not strictly reserved to C++11 features. The purpose of inline namespaces (such as __cxx11 ) is that if eventually a class/struct needs to change in ways that are not backwards compatible, new programs will grab its definition from a new inline namespace while the old definition remains for programs that were built before.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM