Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Copying of ANY stream in C++ is disabled by having made the copy constructor <code>private</code>.</p> <p>Any means ANY, whether it is <code>stringstream</code>, <code>istream</code>, <code>ostream</code>,<code>iostream</code> or whatever.</p> <p>Copying of <em>stream</em> is disabled because it doesn't make sense. Its very very very important to understand what <em>stream</em> means, to actually understand why copying <em>stream</em> does not make sense. <code>stream</code> is not a container that you can make copy of. It doesn't contain data. </p> <p>If a list/vector/map or any container is a bucket, then stream is a hose through which data <em>flows</em>. Think of stream as some pipe <em>through</em> which you get data; a pipe - at one side is the source (sender), on the other side is the sink (receiver). That is called unidirectional stream. There're also bidirectional streams through which data <em>flows</em> in both direction. So what does it make sense making a copy of such a thing? It doesn't contain any data at all. It is <em>through</em> which you get data.</p> <p>Now suppose for a while if making a copy of stream is allowed, and you created a <em>copy</em> of <code>std::cin</code> which is in fact input stream. Say the copied object is <code>copy_cin</code>. Now ask yourself : does it make sense to read data from <code>copy_cin</code> stream when the very same data has already been read from <code>std::cin.</code> No, it doesn't make sense, because the user entered the data only once, the keyboard (or the input device) generated the electric signals only once and they flowed through all other hardwares and low-level APIs only once. How can your program read it <em>twice or more</em>?</p> <p>Hence, creating <em>copy</em> is not allowed, but creating <em>reference</em> is allowed:</p> <pre><code>std::istream copy_cin = std::cin; //error std::istream &amp; ref_cin = std::cin; //ok </code></pre> <p>Also note that you can create another instance of stream and can make it use the same <em>underlying buffer</em> which the old stream is currently using. See this : <a href="https://ideone.com/rijov" rel="noreferrer">https://ideone.com/rijov</a></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