Archived

This topic is now archived and is closed to further replies.

Simple question on cin

This topic is 5116 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I can''t seem to find anything that might answer my question so I''ll ask here. I can pass ''cin'' or ''cout'' for that matter as a reference to a function and I can use it just fine, but at the same time I can also use cin and cout without passing them as an arguments to a custom function. A book of mine had used it in an example where it made it seem necessary to do so with cin in order to read any possible error state in cin when the function returned, but still I can invoke the same function without passing cin to it and still check for failure states in cin well after the function returned. So my question is what is the real purpose of passing cin as istream& to a function? I can''t seem to understand what are the reasons where there is no alternative but to pass it.

Share this post


Link to post
Share on other sites
Maybe if you have a function that doesn't know, and care, from what the input will come. Then you cann pass any type of stream to that function. It could be cin, or an opened file, or any other istream.
If you're sure you want just input from cin, there's no point in passing it as a parameter, for cin is just a global variable, that every function cann access

My Site

[edited by - Quasar3D on December 13, 2003 5:51:13 PM]

Share this post


Link to post
Share on other sites