Operating Systems CS 3100
Weber State University
Popular in Course
verified elite notetaker
Popular in ComputerScienence
This 6 page Class Notes was uploaded by Jamaal Franecki on Wednesday October 28, 2015. The Class Notes belongs to CS 3100 at Weber State University taught by Staff in Fall. Since its upload, it has received 59 views. For similar materials see /class/230778/cs-3100-weber-state-university in ComputerScienence at Weber State University.
Reviews for Operating Systems
Report this Material
What is Karma?
Karma is the currency of StudySoup.
You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!
Date Created: 10/28/15
Streams and Files A Review QM C IIO Overview I iosteams were originally created as an example of C class hierarchy but are now a exible and expressive IO system ITables in Lafore gt ios formatting flags p 571 gt Manipulators p 572 gt ios functions p 573 gt istream functions pp 574575 gt ostream functions pp 575576 gt Error status flagsfunctions pp 577578 gt Mode bits for open pp 596597 9 Parameterized Manipulators See page 572 I Declared in iomanip IAlso used with the operatorltlt gt setiosflagsong flags 32 1bit flags gt resetiosflagslong flags 32 1bit flags gt setbaseint base gt setwint width gt setprecisionint precision gt setfillchar fi QM Additional Manipulators Page I Declared in iostream gt noshowbase Indicate base on output eg Ox gt noshowpos Show 39 for positive values gt nouppercase Display A F for hex and E for exponents gt noshowpoint Show decimal point amp trailing zeros gt noskipws Skip white space on input gt left Leftalign pad on right gt right Rightalign pad on left gt internal Pad between signbase and value gt scientific Scientific notation gt fixed Fixed decimal format 9 File IIO File streams I ifstream Constructor opens a le for reading I ofstream Constructor opens a le for writing I Example ifstream inquotdatafilquot if infail cerr ltlt ERROR unable to open file return ofstream outquotresultfilquot if outfail cerr ltlt ERROR unable to open file return QM Open Modes Note flags can be or ed together see pages 596597 I iosin Open for input I iosout Open for output I iosapp Append data to the end ofthe output le I iosate Go to the end ofthe le when opened I iosnocreate Fail ifthe le does not exist I iostrunc Discard contents of existing le I iosbinary Open in binary mode defaults to text mode I iosnoreplace Do not ovenNrite existing le fail open call I Example ifstream inquotdata lquot iosbinary QM Lineoriented Input CStrings I istreamamp getchar buf int size charterm 39n39 gt Reads until term is found upto a max of size1 chars gt Does not read term character I istreamamp getlinechar buf int size charterm 39n39 gt Reads until term is found upto a max of size1 chars gt Also reads but does not store the term character I Overloaded versions of get gt int get gt istreamamp getchar ampc gt istreamamp getstreambufamp stream char term 39n39 I int gcount reports the number of characters read QM Examples Reading files one line or one character at a time ifstream inquotdatatxtquot int 0 char line128 while lineof cout ltlt charinget int c while 0 inget l EOF coutputc char line128 while ingetlineline 128 NULL cout ltlt line ltlt endl Binary IIO aka block or raw O I istreamamp readchar buffer int nbytes gt Reads nbytes directly into buffer gt int gcount reports the number of bytes actually read I istreamamp writechar buffer int nbytes gt Writes nbytes directly from buffer l Example char buffer1024 int count inreadbuffer 1024 while count inputgcount gt 0 outwritebuffer count inreadbuffer 1024 QM IIO Error Handling See pages 577 and 578 I Errorstatus flags gt goodbit no errors no other flags set flags O gt eofbit at end of file gt failbit io operation failed recoverable gt badbit invalid operation recoverable gt hardfail unrecoverable error I Errorstatus operations gt good No problems gt eof At end of file gt fail Operation failed ie formatting but the buffer is okay gt bad An error has occurred and the buffer may be corrupted gt clear Clears the badbit QM Pointer Arithmetic Addition subtraction and comparison IAssumes a contiguous block of memory ie an array I Allowed operations gt Addsubtract an integer tofrom a pointer p1 i i p2 gt Difference between two pointers p2 p1 i of elements gt Test for inequality if p1 p2 if p1 p2 I No check for addressing out of bounds IThe compiler automatically multiplies and divides by the size in bytes ofthe referenced object in pointer arithmetic p5 p2 p1 p p1p2 p5 p 2 p14 p1 p2
Are you sure you want to buy this material for
You're already Subscribed!
Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'