tailieunhanh - Object Oriented Programming (29)

CSC241: Object Oriented Programming. Lecture No 31. 1 Previous Lecture.• A linked list data storage class. data ptr data ptr data ptr data ptr. ptr private:.struct Node Node* first;.{ public:. TYPE data; void additem(TYPE. Node* next; d);.}; void del();. void display(); 2 Today’s Lecture.• Stream and classes. •. Input and Output stream. •. iostream class. •. ios class. – Formatting Flags. – Error-Status Bits. – File operations. 3 Stream Classes.•. A stream is a flow of data (sequences of bytes).•. In C++ a stream is represented by an object of a. particular class. – For example, the cin and cout stream objects.•. Different streams are used to represent different. kinds of data flow. – For example, the ifstream class represents data flow. from input disk files 4 Advantages of Streams.•. Simplicity. – . using printf and scanf function, there is a need to. specify the type of input or output . %d, %f or %c. etc – There are no such formatting characters in streams,. since each object already knows how to display itself.•. Overload existing operators and functions. – Use exisiting operator for class in the same way as. the built-in types. 5 I/O stream classes.•. It represent input and output stream. – In input stream, the bytes flow from a device (., a. keyboard) to main memory. – In output stream, bytes flow from main memory to a. device (., a display screen, a printer).•. We have already use stream class. – Extraction operator >> is a member of istream class. – Insertion operator << is a member of ostream class.• istream and ostream are derived from ios. 6 cout and cin.•. cout object:. – It representing the standard output stream. which is usually monitor. – It is a predefined object of the. ostream_withassign class, which is derived. from the ostream class.•. cin object:. – Represent standard input stream which is. usually key board. 7 Header files.•. IOSTREAM. – classes used for input and output to the video display. and keyboard are declared in header file IOSTREAM.•. FSTREAM. – classes used specifically for disk file I/O are declared. in the file. 8 iostream class.•. iostream class is derived from both istream and. ostream by multiple inheritance.•. Classes derived from it can be used with disk files, that may be opened for both input and. output at the same time. 9 ios class.•. It is base class of all the stream classes.•. It contains the majority of the features to operate. C++ streams.•. Three most important features are. – Formatting flags,. – Error-status flags,. – File operation mode. 10 Formatting Flags.•. It is a set of flag in ios class.•. Flags act as on/off switches that specify various.

TỪ KHÓA LIÊN QUAN
crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.