2016-08-30 3 views
1

アプリケーションに「110110」を入力すると、2番目のチャンクが「2」を出力し、 。sregex_iteratorを正規表現の可変パターンと組み立てたパターンで使用しているときに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; 
} 
+2

regex_iterator(BidirIt, BidirIt, const regex_type&&, std::regex_constants::match_flag_type) = delete; 
[ 'の#include <ビット/ STDC++ H>'](https://stackoverflow.com/questions/31816095/why-should-i-not-include-bits-stdc-h) –

+1

[this]に関連していることを確かめてください(http://stackoverflow.com/questions/33154890/simple-stdregex-search-code-wont- compile-with-apple-clang-std-c14) – NathanOliver

+0

はい、ビット/ stdC++。h ... compsのクイックタイピングコードの悪い習慣。 iostreamとregexの置き換えは自由に行えます:) – forrest

答えて

3

C++ 14は、コンストラクタを削除することによって、インターフェイスを修正:

+0

「削除」部分がわからないことがあります。しかし、私はstd = C++ 14と-Wallでコンパイルしており、上のアプリケーションを構築する警告は表示されません。 deleteはビルドすべきでないことを示していますか? – forrest

+0

エラー[Demo](http://coliru.stacked-crooked.com/a/9b8abf0a1f3d4997)が必要です。 – Jarod42

+0

ありがとう..私はclangで二重チェックし、実際にエラーを取得します。 gcc-4.9を実行するとエラーは発生しません。私は4.9でC++ 14のサポートがすべてではないと思います – forrest

関連する問題