| | |
What is a stream exactly?
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Jun 2009
Posts: 14
Reputation:
Solved Threads: 0
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.
"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.
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.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
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.
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
(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
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)!!
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
(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
•
•
Join Date: Apr 2009
Posts: 10
Reputation:
Solved Threads: 1
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!
Got my MCSE Certfication in 3 months!
•
•
Join Date: Jun 2009
Posts: 1
Reputation:
Solved Threads: 0
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
![]() |
Similar Threads
- Video stream with ASP.NET (ASP.NET)
- converting codecs of a rtp stream (Java)
- failed to create stream: HTTP wrapper does not support writeable connections (PHP)
- stdin & stream (C)
- read data written to an output stream (Java)
- Noob : Input Stream Trouble (Java)
- Question:: reading from an input stream. (C++)
- i got trapped in a stream of warez sites (Viruses, Spyware and other Nasties)
Other Threads in the C++ Forum
- Previous Thread: Run time error!! solution required
- Next Thread: not sure how to fix this error msg
| Thread Tools | Search this Thread |
api application array arrays based beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg simple sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






