title: What is the relationship between iostream and namespace std?
body: <p>I am currently using <em>Teach Yourself C++ in 21 Days, Second Edition</em> book to learn about C++ coding, along with Microsoft Visual C++ 2010 Express. At the end of Chapter 1, there is a small exercise about writing and compiling the following code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  int main ()
  {
      cout &lt;&lt; "Hello World!\n";
      return 0;
  }
  </code></pre>
  
  <p>Quite simple, right? However to my surprise the code would not compile, due to this error:</p>
  
  <blockquote>
    <p>error C2065: 'cout' : undeclared identifier</p>
  </blockquote>
  
  <p>I began scouring the Web, and soon found some solutions <a href="https://stackoverflow.com/questions/1868603/error-c2065-cout-undeclared-identifier">here</a>. Turns out I had to add
  <code>using namespace std;</code> to my code! </p>
  
  <p>However there was no mention of namespaces in the book, so I figured the book is outdated. (It uses <code>#include &lt;iostream.h&gt;</code> pre-processor directive!) After some more Web research I found a lot of information about namespaces, <code>namespace std</code>, along with some historical background on <code>&lt;iostream.h&gt;</code> and <code>&lt;iostream&gt;</code>, and all this flow of new information is quite confusing to me. (Not to mention all the unnecessary Google results about medical STDs...)</p>
  
  <p>So here are some questions I've got so far:</p>
  
  <ol>
  <li>If I am including the <code>iostream</code> library, why is a <code>namespace</code> needed to find <code>cout</code>? Is there another <code>cout</code> somewhere that could cause a name clash? If someone could provide a diagram for this, that'd be great.</li>
  </ol>
  
  <p>And as a bonus, some historical background:</p>
  
  <ol>
  <li><p>What exactly was <code>iostream.h</code> before it was changed to <code>iostream</code>?</p></li>
  <li><p>Did <code>namespace</code> play a part in this change?</p></li>
  </ol>