Note that there are some explanatory texts on larger screens.

plurals
  1. POusing <map> in C++
    primarykey
    data
    text
    <p>I am trying to use "map" container in C++ in the following way: </p> <ul> <li>Key is a string and mapping value is an object of type ofstream. If I execute the following code, I get an error that is copied at the end of the message. Could someone please let me know what is going wrong? If it can not be done using 'map' is there some other way to create such key:value pair? I would appreciate your response. </li> </ul> <p>Note: If I test the following code with map foo; it works fine. </p> <p>Code:</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>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>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload