title: Cannot std::cout an implicitly converted std::string
body: <p>I used to display an string by <code>std::cout &lt;&lt; str &lt;&lt; std::endl</code>, and thought an object implicitly convertabel to <code>std::string</code> can be also displayed in this way.</p>
  <p>However, I notice that I was wrong. I cannot <code>std::cout</code> an implicitly converted <code>std::string</code> until I overload <code>operator &lt;&lt;</code> for std::string.</p>
  <p>The following code demonstrates the mentioned stuff.</p>
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;stdio.h&gt;
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  
  class X
  {
  public:
      operator std::string() const {
          return std::string(&quot;world&quot;);
      }
  };
  
  #ifdef OVERLOAD_STREAM_OP
  std::ostream&amp; operator&lt;&lt;(std::ostream&amp; os, const std::string&amp; s) {
      return os &lt;&lt; s;
  }
  #endif
  
  int main() {
      std::string s = &quot;hello&quot;;
      std::cout &lt;&lt; s &lt;&lt; std::endl; // viable
      printf(&quot;---\n&quot;);
      X x;
      std::cout &lt;&lt; x &lt;&lt; std::endl; // not viable
  
      return 0;
  }
  </code></pre>
  <p>It seems that, in STL implementation, the overloaded <code>operator &lt;&lt;</code> function for std::string type, is a little bit different (But I really really don't understand those template stuffs):</p>
  <pre class="lang-cpp prettyprint-override"><code>  template&lt;typename _CharT, typename _Traits, typename _Allocator&gt;
      std::basic_ostream&lt;_CharT, _Traits&gt;&amp;
      operator&lt;&lt;(std::basic_ostream&lt;_CharT, _Traits&gt;&amp; __os,
             const basic_string&lt;_CharT, _Traits, _Allocator&gt;&amp; __str)
      { return __os &lt;&lt; __str._M_base(); }
  </code></pre>
  <p>My questions:</p>
  <ol>
  <li><p>What is the difference between STL's overloaded <code>operator &lt;&lt;</code> and my own overloaded <code>operator&lt;&lt;</code> for <code>std::string</code> type?</p>
  </li>
  <li><p>Why I cannot display the implicitly converted std::string object <code>x</code> with <code>std::cout</code>(compile error)?</p>
  </li>
  </ol>