title: Unable to use cout with a C++ string unless I run it through data() or c_str()
body: <p>On the following program, I'm getting this when I attempt to use <code>cout</code> to output a C++ string to <code>stdout</code> - the other instructions produce the expected output.  I'm using MS Visual Studio 2010 on a Windows 7 system.</p>
  
  <blockquote>
    <p>First-chance exception at 0x00dd4e89 in Lab1.exe: 0xC00000FD: Stack
    overflow. Unhandled exception at 0x00dd4e89 in Lab1.exe: 0xC00000FD:
    Stack overflow. The program '[3740] Lab1.exe: Native' has exited with
    code -1073741571 (0xc00000fd).</p>
  </blockquote>
  
  <pre><code>#include "StdAfx.h"
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  #include &lt;iostream&gt;
  #include &lt;ostream&gt;
  #include &lt;string&gt;
  #include &lt;ctime&gt;
  
  //more code here
  
  int main() {
  
  int number = 1;
  string myStr = "Hello, string!";
  cout &lt;&lt; "number: " &lt;&lt; number &lt;&lt; endl;
  cout &lt;&lt; "Hello, World!" &lt;&lt; endl;
  cout &lt;&lt; myStr &lt;&lt; endl;            //failing instruction
  
  cout &lt;&lt; "\nHit any key to continue...." &lt;&lt; endl;
  cin.get();
  
  return 0;
  }
  </code></pre>
  
  <p>My instructor suggested changing the failing instruction to use <code>data()</code> or <code>c_str()</code> like so:</p>
  
  <pre><code>   cout &lt;&lt; myStr.data() &lt;&lt; endl;
  </code></pre>
  
  <p>I did this, and this resolved the problem.  He didn't know why, just said it worked so not to worry about it.</p>
  
  <p>It seems to me that a C++ ostream object like cout should be able to handle a C++ string.  Am I missing something, or do I really need to use <code>data()</code> or <code>c_str()</code> with <code>cout</code>?</p>
  
  <p>I also tried using <code>std::cout</code>, <code>std::string</code>, and <code>std::endl</code> - it didn't help.</p>
  
  <p>Thanks in advance for your advice; I'm really wanting to understand what's going on here.</p>
  
  <p>Helen</p>