title: Using RAII with C++ streams and STL containers?
body: <p>I'm trying to use <a href="http://en.wikipedia.org/wiki/RAII" rel="nofollow noreferrer">RAII</a> concepts with an STL container of ofstream objects.  For example:</p>
  
  <pre><code>int main(int argc, char**argv)
  {
    std::deque&lt;std::ofstream&gt; sList;
  
    sList.push_back(std::ofstream()); // tried variations such as *(new ofstream())
    sList[0].open("test1.txt");
    sList[0] &lt;&lt; "This is a test";
    sList[0].close();
  }
  </code></pre>
  
  <p>However, no matter how I try to tweak the code and declarations, the compiler always complains.  Apparently the copy constructor for std::basic_ios, which lives inside of streams, is private.  Are there any easy plian C++/STL solutions to doing this using RAII, or do I need to get some type of smart pointer involved?</p>