Chapter 12 - C++ Stream Input/Output ppt

80 1.8K 1
Chapter 12 - C++ Stream Input/Output ppt

Đ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

Chapter 12 - C++ Stream Input/Output Outline 12.1 Introduction 12.2 Streams 12.2.1 Classic Streams vs Standard Streams 12.2.2 iostream Library Header Files 12.2.3 Stream Input/Output Classes and Objects 12.3 Stream Output 12.3.1 Output of char * Variables 12.3.2 Character Output using Member Function put 12.4 Stream Input 12.4.1 get and getline Member Functions 12.4.2 istream Member Functions peek, putback and ignore 12.4.3 Type-Safe I/O 12.5 Unformatted I/O using read, write and gcount © 2003 Prentice Hall, Inc All rights reserved Chapter 12 - C++ Stream Input/Output Outline 12.6 Introduction to Stream Manipulators 12.6.1 Integral Stream Base: dec, oct, hex and setbase 12.6.2 Floating-Point Precision (precision, setprecision) 12.6.3 Field Width (width, setw) 12.6.4 Programmer-Defined Manipulators 12.7 Stream Format States and Stream Manipulators 12.7.1 Trailing Zeros and Decimal Points (showpoint) 12.7.2 Justification (left, right and internal) 12.7.3 Padding (fill, setfill) 12.7.4 Integral Stream Base (dec, oct, hex, showbase) 12.7.5 Floating-Point Numbers; Scientific and Fixed Notation (scientific, fixed) 12.7.6 Uppercase/Lowercase Control (uppercase) 12.7.7 Specifying Boolean Format (boolalpha) 12.7.8 Inc All rights and © 2003 Prentice Hall,Setting reserved Resetting the Format State via 12.1 Introduction • Overview common I/O features • C++ I/O – Object oriented • References, function overloading, operator overloading – Type safe • I/O sensitive to data type • Error if types not match – User-defined and standard types ã Makes C++ extensible â 2003 Prentice Hall, Inc All rights reserved 12.2 Streams • Stream: sequence of bytes – Input: from device (keyboard, disk drive) to memory – Output: from memory to device (monitor, printer, etc.) • I/O operations often bottleneck – Wait for disk drive/keyboard input – Low-level I/O • Unformatted (not convenient for people) • Byte-by-byte transfer • High-speed, high-volume transfers – High-level I/O • Formatted • Bytes grouped (into integers, characters, strings, etc.) ã Good for most I/O needs â 2003 Prentice Hall, Inc All rights reserved 12.2.1 Classic Streams vs Standard Streams • Classic streams – Input/output chars (one byte) – Limited number of characters (ASCII) • Standard stream libraries – Some languages need special alphabets – Unicode character set supports this • wchar_t character type – Can I/O with Unicode characters © 2003 Prentice Hall, Inc All rights reserved 12.2.2 iostream Library Header Files • iostream library – Has header files with hundreds of I/O capabilities – • • • • Standard input (cin) Standard output (cout) Unbuffered error (cerr) Buffered error (clog) – • Formatted I/O with parameterized stream manipulators – • File processing operations © 2003 Prentice Hall, Inc All rights reserved 12.2.3 Stream Input/Output Classes and Objects • iostream library has class templates for I/O – basic_istream (stream input) – basic_ostream (stream output) – basic_iostream (stream input and output) • typedef declares alias for data type – typedef Card *CardPtr; • CardPtr synonym for Card * – typedefs istream, ostream, iostream • Allow char I/O • Use these typedefs in chapter © 2003 Prentice Hall, Inc All rights reserved 12.2.3 Stream Input/Output Classes and Objects • Templates "derive" from basic_ios basic_ios basic_istream basic_ostream basic_iostream © 2003 Prentice Hall, Inc All rights reserved 12.2.3 Stream Input/Output Classes and Objects • > – Stream insertion and extraction operators • cin – istream object – Connected to standard input (usually keyboard) – cin >> grade; • Compiler determines data type of grade • Calls proper overloaded operator • No extra type information needed © 2003 Prentice Hall, Inc All rights reserved 12.2.3 Stream Input/Output Classes and Objects • cout – ostream object – Standard output (usually display screen) – cin

Ngày đăng: 10/03/2014, 06:20

Từ khóa liên quan

Mục lục

  • Chapter 12 - C++ Stream Input/Output

  • Slide 2

  • 12.1 Introduction

  • 12.2 Streams

  • 12.2.1 Classic Streams vs. Standard Streams

  • 12.2.2 iostream Library Header Files

  • 12.2.3 Stream Input/Output Classes and Objects

  • Slide 8

  • Slide 9

  • Slide 10

  • Slide 11

  • Slide 12

  • 12.3 Stream Output

  • 12.3.1 Output of char * Variables

  • fig12_03.cpp (1 of 1) fig12_03.cpp output (1 of 1)

  • 12.3.2 Character Output using Member Function put

  • 12.4 Stream Input

  • 12.4.1 get and getline Member Functions

  • fig12_04.cpp (1 of 2)

  • fig12_04.cpp (2 of 2) fig12_04.cpp output (1 of 1)

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

Tài liệu liên quan