Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 为什么在使用sregex_迭代器和regex变量模式以及构造模式时会得到两个不同的结果_C++_Regex_Stl - Fatal编程技术网

C++ 为什么在使用sregex_迭代器和regex变量模式以及构造模式时会得到两个不同的结果

C++ 为什么在使用sregex_迭代器和regex变量模式以及构造模式时会得到两个不同的结果,c++,regex,stl,C++,Regex,Stl,如果我在应用程序中输入“110110”,则第一个块打印出“1”,而第二个块打印出“2” 为什么结果不同 如何在函数调用中构造正则表达式模式 #include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; auto begin = sregex_iterator(s.begin(),s.end(),regex{R"(110)"}); auto en

如果我在应用程序中输入“110110”,则第一个块打印出“1”,而第二个块打印出“2”

为什么结果不同

如何在函数调用中构造正则表达式模式

#include <bits/stdc++.h>
using namespace std;
int main() {
    string s;
    cin >> s;

    auto begin = sregex_iterator(s.begin(),s.end(),regex{R"(110)"});
    auto end = sregex_iterator();
    cout << distance(begin,end) << endl;

    const regex r(R"(110)");
    begin = sregex_iterator(s.begin(),s.end(),r);
    end = sregex_iterator();
    cout << distance(begin,end) << endl;
}
#包括
使用名称空间std;
int main(){
字符串s;
cin>>s;
auto begin=sregex_迭代器(s.begin(),s.end(),regex{R“(110)”});
自动结束=sregx_迭代器();

coutC++14通过删除构造函数修复了接口:

regex_iterator(BidirIt, BidirIt,
               const regex_type&&,
               std::regex_constants::match_flag_type) = delete;

非常确定它与Yes,bits/stdc++.h有关。快速键入comps代码的坏习惯。请随意替换iostream和regex includes:)在regex_迭代器的文档中找到了这一点:注意,程序员有责任确保传递给迭代器构造函数的std::basic_regex对象比迭代器的寿命长。B因为迭代器存储一个指向正则表达式的指针,在正则表达式被销毁后增加迭代器将访问一个悬空指针。所以我想这只是一个编译器不关心的情况,程序员必须警惕悬空指针。也许我不理解“删除”部分。但我使用std=c++14和-Wall编译,在构建上述应用程序时没有收到任何警告。delete是否表示不应构建该应用程序?您应该有错误。谢谢..我用clang仔细检查了一遍,确实收到了错误。运行gcc-4.9不会导致任何错误。我想4.9中的c++14支持还不够