title: c++ how does cout print a char*
body: <p>In the code below, the function <code>getName()</code> returns a <code>char *</code>. I would of thought that it should (it also can) return a <code>string</code>. How does <code>cout</code> correctly print it to the console if it is just a pointer to the first char?</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  class Base
  {
  protected:
      int m_value;
  
  public:
      Base(int value)
          : m_value(value)
      {
      }
  
      const char* getName() { return "Base"; }
      //string getName() { return "Base"; }
      int getValue() { return m_value; }
  };
  
  
  int main()
  {
      Base base(5);
      std::cout &lt;&lt; "Base is a " &lt;&lt; base.getName() &lt;&lt; " and has value " &lt;&lt; base.getValue() &lt;&lt; '\n';
  
  
      return 0;
  }
  </code></pre>