C++: Why I can't pass a pair of iterators to regex_search?

后端 未结 2 661
醉话见心
醉话见心 2021-01-26 22:46

I try to pass a pair of iterators to represent a string sequence:

    #include
    #include
    using namespace std;
    int main(int          


        
2条回答
  •  日久生厌
    2021-01-26 23:05

    regex_search expects a const_iterator but you are passing a std::string::iterator.


    Make your string const

    const string test("abc");
    

    Declare a const_iterator

    std::string::const_iterator iter = test.begin();
    std::string::const_iterator end = test.end();
    

    Or use cbegin and cend

    auto iter = test.cbegin();
    auto end = test.cend();
    

提交回复
热议问题