Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>I don't understand what this ostream function declaration means:</p> </blockquote> <pre><code>ostream&amp; operator&lt;&lt; (ostream&amp; (*pf)(ostream&amp;)); </code></pre> <p>Have you seen functions like <code>std::endl</code>, <code>std::flush</code>, <code>std::hex</code>, <code>std::dec</code>, <code>std::setw</code>...? They can all be "sent" to a stream using "&lt;&lt;", then they get called with the stream as a function argument and do their magic on the stream. They actually match the <code>ostream&amp; (*pf)(ostream&amp;)</code> argument above, and that operator's the one that lets them be used. If we look at the Visual C++ implementation...</p> <pre><code> _Myt&amp; operator&lt;&lt;(_Myt&amp; (__cdecl *_Pfn)(_Myt&amp;)) { return ((*_Pfn)(*this)); } </code></pre> <p>...you can see if just calls the function, passing the stream it's used on as an argument. The functions are expected to return a reference to the same stream argument, so that further <code>&lt;&lt;</code> operations may be chained, or the stream may be implicitly converted to <code>bool</code> as a test of stream state.</p> <p>See <a href="http://en.cppreference.com/w/cpp/io/manip" rel="nofollow">http://en.cppreference.com/w/cpp/io/manip</a> for more information about io manipulators.</p> <p>You wanted help with:</p> <pre><code>void print(ostream&amp; os){ cout &lt;&lt; os; } </code></pre> <p>The issue here is that you're sending the <code>ostream</code> argument to another stream - <code>cout</code> - and it doesn't know what you want it to do with it.</p> <p>To send the current <em>content</em> of <code>os</code> to <code>cout</code>, try:</p> <pre><code>void print(ostream&amp; os){ cout &lt;&lt; os.rdbuf(); } </code></pre> <p>Or if you want to print some actual data to the stream represented by the argument:</p> <pre><code>void print(ostream&amp; os){ os &lt;&lt; "show this!\n"; } print(std::cout); // to write "show this!\n" to `std::cout` print(std::cerr); // to write "show this!\n" to `std::cerr` </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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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