#3163 closed Bugs (invalid)
Regex use - compile error
Reported by: | Owned by: | John Maddock | |
---|---|---|---|
Milestone: | Boost 1.40.0 | Component: | regex |
Version: | Boost 1.39.0 | Severity: | Problem |
Keywords: | regex, compile | Cc: |
Description
Hi, I have problem in my little test program:
std::string decoded = "this is standart string with username=\"myusername\" etc. "; static const boost::regex regUsername("username=\"(.*)\""); boost::cmatch matches; std::string::const_iterator begin; begin = decoded.begin(); while(boost::regex_search(begin, decoded.end(), matches, regUsername)){ std::string text(matches[1].first, matches[1].second); std::cout << "OUTPUT: " << text << std::endl; begin = matches[1].second; }
compile error:
ccache g++ -o test.o -c -O2 -Wno-deprecated -Wall -Iinc test.cpp test.cpp: In member function ‘void authorization()’: test.cpp:211: error: no matching function for call to ‘regex_search(__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >&, __gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, boost::cmatch&, const boost::regex&)’ test.cpp:214: error: no match for ‘operator=’ in ‘begin = ((const boost::sub_match<const char*>*)matches.boost::match_results<BidiIterator, Allocator>::operator[] [with BidiIterator = const char*, Allocator = std::allocator<boost::sub_match<const char*> >](1))->boost::sub_match<const char*>::<anonymous>.std::pair<const char*, const char*>::second’ /usr/lib/gcc/i686-pc-linux-gnu/4.4.0/../../../../include/c++/4.4.0/bits/stl_iterator.h:669: note: candidates are: __gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >& __gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >::operator=(const __gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >&) scons: *** [test.o] Error 1
Change History (4)
comment:1 by , 13 years ago
comment:2 by , 13 years ago
I try both iterators std::string::const_iterator and std::string::iterator and compile errors is still there.
try this:
std::string::const_iterator begin; begin = decoded.begin(); std::string::const_iterator end; end = decoded.end();
or this:
std::string::iterator begin; begin = decoded.begin(); std::string::iterator end; end = decoded.end();
errors are same..
comment:3 by , 13 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
Steven was almost correct: you're using cmatch which is a typedef for match_results<const char*>, but then passing string iterators to the function. Use the typedef boost::smatch with string iterators.
HTH, John.
Note:
See TracTickets
for help on using tickets.
The two iterators have different types. You're passing a std::string::const_iterator as the first argument to regex_search and a std::string::iterator as the second argument.