15.13 The Stream Buffer Classes
As mentioned in Section 15.2.1, page 749, reading and writing are not done by the streams directly
but are delegated to stream buffers.
The general interface to deal with stream buffers is pretty simple (see Section 15.12.2, page 820):
• rdbuf() yields a pointer to the stream buffer of a stream.
• The constructor and rdbuf() of streams allow setting a stream buffer at construction time or
changing the stream buffer while the stream exists. In both cases, you have to pass a pointer to
the stream buffer, which is what rdbuf() returns.
This ability can be used to let streams write to the same output device (see Section 15.12.2, page 820,
to redirect streams (see Section 15.12.3, page 822), read from and write to the same buffer (see
Section 15.12.4, page 824), or use other character encodings, such as UTF-8 or UTF-16/UCS-2, as
input and output format (see Section 16.4.4, page 903).
This section describes how the stream buffer classes operate. The discussion not only gives a
deeper understanding of what is going on when I/O streams are used but also provides the basis to
define new I/O channels. Before going into the details of stream buffer
15.13 เรียนบัฟเฟอร์กระแส
ดังกล่าวในมาตรา 15.2.1, หน้า 749, การอ่านและการเขียนที่ไม่ได้ทำโดยกระแสโดยตรง
แต่จะมีการมอบหมายให้กระแสบัฟเฟอร์
อินเตอร์เฟซทั่วไปที่จะจัดการกับบัฟเฟอร์กระแสสวยเรียบง่าย (ดูมาตรา 15.12.2 , หน้า 820)
• rdbuf () อัตราผลตอบแทนที่ชี้ไปยังบัฟเฟอร์กระแสของกระแส
•สร้างและ rdbuf () ลำธารช่วยให้การตั้งค่าบัฟเฟอร์กระแสในเวลาการก่อสร้างหรือ
การเปลี่ยนกันชนกระแสในขณะที่กระแสที่มีอยู่ ในทั้งสองกรณีที่คุณต้องผ่านตัวชี้ไปยัง
บัฟเฟอร์กระแสซึ่งเป็นสิ่งที่ rdbuf () กลับ
ความสามารถนี้สามารถนำมาใช้เพื่อให้กระแสเขียนกับอุปกรณ์ส่งออกเดียวกัน (ดูมาตรา 15.12.2, หน้า 820
เปลี่ยนเส้นทางลำธาร (ดูมาตรา 15.12.3, หน้า 822) อ่านจากและเขียนไปยังบัฟเฟอร์เดียวกัน (ดู
มาตรา 15.12.4, หน้า 824) หรือใช้การเข้ารหัสตัวอักษรอื่น ๆ เช่น UTF-8 หรือ UTF-16/UCS-2, เป็น
input และ output รูปแบบ (ดูมาตรา 16.4.4, หน้า 903)
ในส่วนนี้จะอธิบายถึงวิธีการสตรีมชั้นเรียนบัฟเฟอร์ทำงาน. การอภิปรายไม่เพียง แต่ให้
ความรู้ความเข้าใจในสิ่งที่เกิดขึ้นเมื่อ I / O ลำธารถูกนำมาใช้ แต่ยังให้ พื้นฐานในการ
กำหนดช่อง I / O ใหม่. ก่อนที่จะลงรายละเอียดของ buffer กระแส
การแปล กรุณารอสักครู่..
![](//thimg.ilovetranslation.com/pic/loading_3.gif?v=b9814dd30c1d7c59_8619)