title: Cannot pass sregex_iterator as a stream to cout
body: <p>I save the following file as first.cpp</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;regex&gt;
  using namespace std;
  
  int main (){
  
      regex filenameRegex("[a-zA-Z_][a-zA-Z_0-9]*\\.[a-zA-Z0-9]+");
  
      string s2 = "Filenames are readme.txt and my.cmd.";
  
      sregex_iterator it(s2.begin(), s2.end(), filenameRegex);
      sregex_iterator it_end;
  
      while(it != it_end){
          cout &lt;&lt; (*it) &lt;&lt; endl;
          ++it;
      }
  
      return 0;
  }
  </code></pre>
  
  <p>Attempting to compile it with the command g++ first.cpp -o first -std=c++11 produces the following error:</p>
  
  <pre><code>first.cpp: In function ‘int main()’:
  first.cpp:16:15: error: cannot bind ‘std::ostream {aka std::basic_ostream&lt;char&gt;}’ lvalue to ‘std::basic_ostream&lt;char&gt;&amp;&amp;’
     cout &lt;&lt; (*it) &lt;&lt; endl;
                 ^
  In file included from /usr/include/c++/4.9/iostream:39:0,
                   from first.cpp:1:
  /usr/include/c++/4.9/ostream:602:5: note: initializing argument 1 of ‘std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::operator&lt;&lt;(std::basic_ostream&lt;_CharT, _Traits&gt;&amp;&amp;, const _Tp&amp;) [with _CharT = char; _Traits = std::char_traits&lt;char&gt;; _Tp = std::match_results&lt;__gnu_cxx::__normal_iterator&lt;const char*, std::basic_string&lt;char&gt; &gt; &gt;]’
       operator&lt;&lt;(basic_ostream&lt;_CharT, _Traits&gt;&amp;&amp; __os, const _Tp&amp; __x)
  </code></pre>
  
  <p>I am very confused about what is going on here. The tutorial <a href="http://www.informit.com/articles/article.aspx?p=2079020" rel="nofollow">here</a> states that deferenceing an sregex_iterator object should return a string. Is this not true?</p>