DOC PREVIEW
IUPUI CS 265 - Input/Output Streams, Part 1

This preview shows page 1-2-19-20 out of 20 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 20 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 20 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 20 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 20 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 20 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Department of Computer and Information Science, School of Science, IUPUIC++ Stream I/OStreamsLibrary: Header Filesiostream LibraryStream InputStream Outputiostream - ExampleOutput of char * VariablesCharacter Output with “put”Stream StatesCharacter InputCharacter Input - cin.get()Character Input - cin.getline()Character Input – cin.ignore()cin.putback() and cin.peek()Unformatted I/Oread()write()Character I/O - Example01/14/19 1Dale RobertsDepartment of Computer and Information Science,School of Science, IUPUIDale Roberts, LecturerComputer Science, IUPUIE-mail: [email protected]/Output Streams, Part 1Input/Output Streams, Part 101/14/19 2Dale RobertsC++ Stream I/OC++ Stream I/OOne of the complex features of C++.One of the complex features of C++.Many I/O features are object oriented.Many I/O features are object oriented.Type safe -- performed in a manner sensitive to the type Type safe -- performed in a manner sensitive to the type of the data.of the data.Less error prone -- removes redundant type Less error prone -- removes redundant type specifications.specifications.Extensible -- new user defined types can also be used in Extensible -- new user defined types can also be used in the same way as predefined types.the same way as predefined types.Derivable -- these are real classes and hence can be Derivable -- these are real classes and hence can be derived and extended.derived and extended.01/14/19 3Dale RobertsStreamsStreamsI/O occurs in streams of bytes – A stream is a I/O occurs in streams of bytes – A stream is a sequence of bytes.sequence of bytes.The system I/O mechanisms are responsible for The system I/O mechanisms are responsible for moving bytes from/to devices to/from memory in moving bytes from/to devices to/from memory in a consistent and a reliable manner.a consistent and a reliable manner.Provides "low level" and "high level" I/O Provides "low level" and "high level" I/O capabilities.capabilities.Low level - unformatted I/O - individual bytes – Low level - unformatted I/O - individual bytes – fast.fast.High level - bytes grouped into meaningful units.High level - bytes grouped into meaningful units.01/14/19 4Dale RobertsLibrary: Header FilesLibrary: Header FilesC++ iostream library provides hundreds of I/O capabilities.C++ iostream library provides hundreds of I/O capabilities.iostream.h -- interface to the stream library – contains basic iostream.h -- interface to the stream library – contains basic information required for all I/O operations – contains cin, cout, cerr, information required for all I/O operations – contains cin, cout, cerr, clog objects.clog objects.stream.h -- a subset provided as a compatibility to older stream stream.h -- a subset provided as a compatibility to older stream libraries.libraries.iomanip.h -- for performing formatted I/O with parameterized stream iomanip.h -- for performing formatted I/O with parameterized stream manipulators.manipulators.fstream.h -- user controlled file processing.fstream.h -- user controlled file processing.strstream.h -- in-memory formatting of strings.strstream.h -- in-memory formatting of strings.stdiostream.h -- mix of C and C++ style I/O functions.stdiostream.h -- mix of C and C++ style I/O functions.01/14/19 5Dale Robertsiostream Libraryiostream Library istream class (stream-input operations), ostream class (stream output istream class (stream-input operations), ostream class (stream output oprations), iostream class (supports both stream I/O operations)oprations), iostream class (supports both stream I/O operations) ios class -> istream/ostream classes -> iostream classios class -> istream/ostream classes -> iostream classOperator overloading provides a convenient notation for performing I/OOperator overloading provides a convenient notation for performing I/O<< (left shift operator) - stream output - “stream insertion operator”<< (left shift operator) - stream output - “stream insertion operator”>> (right shift operator) - stream input - “stream extraction operator>> (right shift operator) - stream input - “stream extraction operator””<< & >> are used with cin, cout, cerr, clog and user defined stream objects.<< & >> are used with cin, cout, cerr, clog and user defined stream objects.cin - an object of istream class and is “tied” to the standard input device.cin - an object of istream class and is “tied” to the standard input device.cout - an object of ostream class and is “tied” to the standard output device.cout - an object of ostream class and is “tied” to the standard output device.cerr - an object of ostream class and is “tied” to the standard error device. Output cerr - an object of ostream class and is “tied” to the standard error device. Output to cerr is unbuffered.to cerr is unbuffered.clog - similar to cerr, but buffered.clog - similar to cerr, but buffered.01/14/19 6Dale RobertsStream InputStream Inputcincin (pronounced as see-in) is a replacement  (pronounced as see-in) is a replacement for scanf( ) function in C++.for scanf( ) function in C++.The The cincin statement sets the value of a variable  statement sets the value of a variable to the value input from the keyboard.to the value input from the keyboard.Skips all the white spaces and line breaks.Skips all the white spaces and line breaks.Does not check for the type of the input – Does not check for the type of the input – “smart”. “smart”. Syntax: cin >> variable1 >> variable2 >> Syntax: cin >> variable1 >> variable2 >> variable3.....; variable3.....; Cascading allowed -- >> associates from left to right and Cascading allowed -- >> associates from left to right and returns a reference to its left operand, i.e., cinreturns a reference to its left operand, i.e., cinExample:Example:cin >> nNumber >> cChar; cin >> fWeight; cin >> fVolume cin >> nNumber >> cChar; cin >> fWeight; cin >> fVolume >> sLength; >> sLength;01/14/19 7Dale RobertsStream OutputStream Outputcoutcout (pronounced as see-out) is the replacement for (pronounced as see-out) is the replacement for printf( ) in C++. printf( ) in C++. Type safe and easy to use.Type safe and easy to use.Multiple statements can be chained together.Multiple statements can be chained together.Syntax: cout << var1 << " Some Text " << var2 << ..... << Syntax: cout << var1 << " Some Text " << var2 << ..... << endl; endl; << associates from left to right – the overloaded << operator


View Full Document

IUPUI CS 265 - Input/Output Streams, Part 1

Download Input/Output Streams, Part 1
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Input/Output Streams, Part 1 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Input/Output Streams, Part 1 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?