title: How can I set up a map with string as key and ostream as value?
body: <p>I am trying to use the <code>map</code> container in C++ in the following way: The Key is a <code>string</code> and the value is an object of type <code>ofstream</code>. My code looks as follows:</p>
  
  <pre><code>#include &lt;string&gt;
  #include &lt;iostream&gt;
  #include &lt;map&gt;
  #include &lt;fstream&gt;
  
  using namespace std;
  
  int main()
  {
    // typedef map&lt;string, int&gt; mapType2;
    // map&lt;string, int&gt; foo;
  
    typedef map&lt;string, ofstream&gt; mapType;
    map&lt;string, ofstream&gt; fooMap;
  
    ofstream foo1;
    ofstream foo2; 
  
    fooMap["file1"] = foo1;
    fooMap["file2"] = foo2;
  
    mapType::iterator iter = fooMap.begin();
    cout&lt;&lt; "Key = " &lt;&lt;iter-&gt;first;
  }
  </code></pre>
  
  <p>However, when I try to compile the above code, I get the following error:</p>
  
  <pre><code>C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/bits/ios_base.h:
  In member function `std::basic_ios&lt;char, std::char_traits&lt;char&gt; &gt;&amp; std::basic_ios&lt;char, std::char_traits&lt;char&gt; &gt;::operator=(const std::basic_ios&lt;char, std::char_traits&lt;char&gt; &gt;&amp;)': 
  C:/Dev-Cpp/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/bits/ios_base.h:741:
  error: `std::ios_base&amp; std::ios_base::operator=(const std::ios_base&amp;)' is private
  hash.cpp:88: error: within this context
  </code></pre>
  
  <p>What is going wrong? If this cannot be done using <code>map</code>, is there some other way to create such key:value pair?</p>
  
  <p>Note: If I test my code with <code>map&lt;string, int&gt; foo;</code> it works fine.</p>