Boost C++ Libraries: Ticket #3163: Regex use - compile error https://svn.boost.org/trac10/ticket/3163 <p> Hi, I have problem in my little test program: </p> <pre class="wiki"> 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 &lt;&lt; "OUTPUT: " &lt;&lt; text &lt;&lt; std::endl; begin = matches[1].second; } </pre><p> compile error: </p> <pre class="wiki">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&lt;const char*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;&amp;, __gnu_cxx::__normal_iterator&lt;char*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, boost::cmatch&amp;, const boost::regex&amp;)’ test.cpp:214: error: no match for ‘operator=’ in ‘begin = ((const boost::sub_match&lt;const char*&gt;*)matches.boost::match_results&lt;BidiIterator, Allocator&gt;::operator[] [with BidiIterator = const char*, Allocator = std::allocator&lt;boost::sub_match&lt;const char*&gt; &gt;](1))-&gt;boost::sub_match&lt;const char*&gt;::&lt;anonymous&gt;.std::pair&lt;const char*, const char*&gt;::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&lt;const char*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;&amp; __gnu_cxx::__normal_iterator&lt;const char*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;::operator=(const __gnu_cxx::__normal_iterator&lt;const char*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;&amp;) scons: *** [test.o] Error 1 </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/3163 Trac 1.4.3 Steven Watanabe Wed, 10 Jun 2009 03:58:00 GMT <link>https://svn.boost.org/trac10/ticket/3163#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3163#comment:1</guid> <description> <p> 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. </p> </description> <category>Ticket</category> </item> <item> <author>scippio@…</author> <pubDate>Wed, 10 Jun 2009 08:05:09 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3163#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3163#comment:2</guid> <description> <p> I try both iterators std::string::const_iterator and std::string::iterator and compile errors is still there. </p> <p> try this: </p> <pre class="wiki">std::string::const_iterator begin; begin = decoded.begin(); std::string::const_iterator end; end = decoded.end(); </pre><p> or this: </p> <pre class="wiki">std::string::iterator begin; begin = decoded.begin(); std::string::iterator end; end = decoded.end(); </pre><p> errors are same.. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Wed, 10 Jun 2009 08:31:56 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/3163#comment:3 https://svn.boost.org/trac10/ticket/3163#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">invalid</span> </li> </ul> <p> Steven was almost correct: you're using cmatch which is a typedef for match_results&lt;const char*&gt;, but then passing string iterators to the function. Use the typedef boost::smatch with string iterators. </p> <p> HTH, John. </p> Ticket scippio@… Wed, 10 Jun 2009 09:02:22 GMT <link>https://svn.boost.org/trac10/ticket/3163#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3163#comment:4</guid> <description> <p> You have true... sorry for stupid ticket :( </p> </description> <category>Ticket</category> </item> </channel> </rss>