Lecture Object oriented programming - Lecture No 32

21 29 0
Lecture Object oriented programming - Lecture No 32

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

This chapter presents the following content: GUI overview, event-driven programming basics, GUI classes and packages, a simple window program, JFrame Class, Java components, JLabel component, JTextField Component, Component Listeners, interfaces, inner classes, anonymous inner classes, jbutton component, JOptionPane Dialog Box, distinguishing between multiple events, using GetActionCommand to distinguish between multiple events (optional), color.

CSC241: Object Oriented Programming Lecture No 32 Previous Lecture • Stream and classes • Input and Output stream • iostream class • ios class – Formatting Flags – Error-Status Bits – Formatted File I/O » Reading data » Writing data Today’s Lecture • File operations • Formatted File I/O • Reading data • Writing data • Character I/O • Binary I/O • Object I/O Character I/O • • put() and get() functions, can be used to output and input single characters These are member of ostream and istream, respectively Go to program • Another way is to use rdbuf() function ifstream infile(“TEST.TXT”); cout name; cout > age; } }; main() { person pers; pers.getData(); ofstream outfile(“PERSON.DAT”, ios::binary); outfile.write(reinterpret_cast(&pers), sizeof(pers)); Go to program Compatible Data Structures • • • • Reading and writing object can – belong to same class of objects – or if classes are different then they must have same data members (without virtual functions) Person class object occupy 40 + = 44 bytes Make sure a class used to read an object is identical to the class used to write it Also not attempt disk I/O with objects that have pointer data members Go to program 10 I/O with Multiple Objects class person { protected: char name[40]; int age; public: void getData() { cout name; cout age; } void showData() { cout

Ngày đăng: 20/09/2020, 13:31

Mục lục

  • Slide 1

  • Previous Lecture

  • Today’s Lecture

  • Character I/O

  • Binary I/O

  • binary input and output with integers

  • reinterpret_cast operator

  • Object I/O

  • Writing/reading an Object to Disk

  • Compatible Data Structures

  • I/O with Multiple Objects

  • The Mode Bits

  • File Pointers

  • Cont.

  • Example: Modify record

  • Seek function

  • Cont.

  • Slide 18

  • Example program

  • File I/O with Member Functions

Tài liệu cùng người dùng

Tài liệu liên quan