Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>For starters, to clarify your terminology, the STL usually refers to the subset of the C++ standard library containing the containers, iterators, and algorithms. The streams classes are part of the C++ standard library, but are usually not bundled together with the STL. Some purists will insist that there is no such thing as the STL in the C++ standard library (since the STL is, technically speaking, a third-party library that was adopted into the standard), but most C++ programmers will know what you mean.</p> <p>As for your question, there is no way within the standard to specify permission modes with <code>ofstream</code>. If you want to create your own custom stream class that is like <code>ofstream</code> but which supports permissions, your best bet would be to do the following:</p> <ol> <li><p>Create a subclass of <code>basic_streambuf</code> that allows you to open, write, and possibly read files while specifying Unix permissions. The streams classes are designed so that the details of communicating with physical devices like disk, networks, and the console are all handled by the <code>basic_streambuf</code> class and its derived classes. If you want to make your own stream class, implementing a stream buffer would be an excellent first step.</p></li> <li><p>Define your own class that subclasses <code>basic_ostream</code> and installs your custom <code>basic_streambuf</code>. By default, the <code>basic_ostream</code> supports all of the standard output routines by implementing them in terms of the underlying <code>basic_streambuf</code> object. Once you have your own stream buffer, building a <code>basic_ostream</code> class that uses that <code>streambuf</code> will cause all of the standard stream operations on that class (such as <code>&lt;&lt;</code>) to start making the appropriate calls to your <code>streambuf</code>.</p></li> </ol> <p>If you'd like more details on this, an excellent reference is <a href="http://rads.stackoverflow.com/amzn/click/0201183951" rel="nofollow">Standard C++ IOStreams and Locales</a>. As a shameless plug, I have used the techniques from this book to build <a href="http://keithschwarz.com/interesting/code/?dir=nstream" rel="nofollow">a stream class that wraps a socket connection</a>. While a lot of the code in my stream won't be particularly useful, the basic structure should help you get started.</p> <p>Hope this helps!</p>
 

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