What is a stream exactly?

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jun 2009
Posts: 14
Reputation: gnobber is an unknown quantity at this point 
Solved Threads: 0
gnobber gnobber is offline Offline
Newbie Poster

What is a stream exactly?

 
0
  #1
Jun 9th, 2009
Hi, im just beginning c++ and been reading regarding cin and cout. After reading the chapter, I just got curious what acually a stream is. It is said in some as a series of characters. In a site:

"A stream is an abstraction that represents a device on which input and ouput operations are performed. A stream can basically be represented as a source or destination of characters of indefinite length."

Represents a device? Does that mean a stream can come from or is an abstraction if an IO device (mouse, trackball, printer, etc). Please help me get this cleared up.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 1,679
Reputation: vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold 
Solved Threads: 193
vmanes's Avatar
vmanes vmanes is offline Offline
Posting Virtuoso

Re: What is a stream exactly?

 
0
  #2
Jun 9th, 2009
Printer - yes. Mouse/trackball, not so much. A stream is the source or destination of a series of data, either characters, or in the case of binary files, a sequence of bytes that represent memory content. Since it's an abstraction, you can operate on any stream in the same manner - it doesn't matter if you're reading characters from a console (keyboard) with cin or from a file with an ifstream object.
Everyone's gotta believe in something. I believe I'll have another drink.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 793
Reputation: siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of 
Solved Threads: 135
siddhant3s's Avatar
siddhant3s siddhant3s is offline Offline
Master Poster

Re: What is a stream exactly?

 
0
  #3
Jun 9th, 2009
Ok, What you want is a bit informal explanation.
Think of stream as a virtual device (presumably a printer). You are give functions to read/write to that device. You actually don't differentiate if that device is actually your monitor, your printer, the hard disk, or the RAM. What you know is that if you have to write or read any of these devices, you can use the same set of functions to do so.
In C++, there are filestream (which can be assume to be a device as hard disk), memorystream( which can be assume to be a device as your RAM), iostream (which can be assume to be a device as monitor for printing and k/b for reading).

You can use the same >> and << operators to read/write from a file, memory, monitor/keyboard, without knowing the specification of each. Thus you save remembering exclusive function for each of these devices.
Siddhant Sanyam
(Not posting much)
Migrate to Standard C++ :When to tell your C++ Code is Non-Standard.
Please Read before posting: How To Ask Questions The Smart Way
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 14
Reputation: gnobber is an unknown quantity at this point 
Solved Threads: 0
gnobber gnobber is offline Offline
Newbie Poster

Re: What is a stream exactly?

 
0
  #4
Jun 9th, 2009
vmanes, siddhant3s:

Thanks so much for the explanation. That really cleared it up (especially the abstraction part). The only thing that is left unclear to me is the mouse/trackball part.

It is an input device so why is it not part of iostream (or any stream)?

Thank you very much for the replies.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 793
Reputation: siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of 
Solved Threads: 135
siddhant3s's Avatar
siddhant3s siddhant3s is offline Offline
Master Poster

Re: What is a stream exactly?

 
0
  #5
Jun 9th, 2009
Tell me something: Can you read words or text from mouse? no.
Well this was very vague conclusion though,
Mouse streams are possible. But, mouse is an optional component of a computer. C++ trace back to those years computer when monitors were new technology!!
So, of course you can read mouse (the location of its pointer) and write mouse (set the position of pointer) but that would be a OS specific issue. Each OS will give different control over mouse. Hence they are not part of standard streams. They are not shipped with every compiler.

Note that when you are well verse in C++, you would be able to create your own mouse stream on WIndows( or perhaps Linux)!!
Siddhant Sanyam
(Not posting much)
Migrate to Standard C++ :When to tell your C++ Code is Non-Standard.
Please Read before posting: How To Ask Questions The Smart Way
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 10
Reputation: certifmix123 has a little shameless behaviour in the past 
Solved Threads: 1
certifmix123 certifmix123 is offline Offline
Newbie Poster

Re: What is a stream exactly?

 
0
  #6
Jun 9th, 2009
Well, all I can say is if that stream will be out in the program you cannot process you're program completely, so if I were you just follow the syntax.
Certification tutorials, articles and products at MCSE Certfication

Got my MCSE Certfication in 3 months!
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 14
Reputation: gnobber is an unknown quantity at this point 
Solved Threads: 0
gnobber gnobber is offline Offline
Newbie Poster

Re: What is a stream exactly?

 
0
  #7
Jun 9th, 2009
Thank you all for the responses. It's clear now especially siddhant3s' explanation. Thanks again!
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 1
Reputation: sai sushma is an unknown quantity at this point 
Solved Threads: 0
sai sushma sai sushma is offline Offline
Newbie Poster

Re: What is a stream exactly?

 
0
  #8
Jun 9th, 2009
A stream is an abstraction that either produces or consumes information.It is linked to a physical device by java I/O system.An input stream can abstract many different kinds of input:from a disc file,keyboard or network socket.in the same way output stream refers to a console.Streams are a clean way to deal with input/output without having every part of your code understand the difference between keyboard and a network
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC