簡體   English   中英

'multiline'不是'std :: __ cxx11 :: regex'的成員

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

我正在嘗試使用以下命令編譯以下C ++代碼:

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;
};

但是得到以下編譯時錯誤

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

當我指定-std = c ++ 17時,為什么g ++使用__cxx11 :: regex?

cppreference.com/w/cpp/regex/basic_regexregex::multiline定義為C++17標准的一部分

Libstdc ++似乎未實現regex::multiline

請注意,它使用的是std::__cxx11::regex並不意味着您被困在過去。 __cxx11並非嚴格保留給C ++ 11功能。 內聯名稱空間 (例如__cxx11的目的是,如果最終一個類/結構需要以不向后兼容的方式進行更改,則新程序將從新的內聯名稱空間中獲取其定義,而舊定義仍保留用於已構建的程序之前。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM