Skip to Content
C++程序设计:原理与实践(基础篇)(原书第2版)
book

C++程序设计:原理与实践(基础篇)(原书第2版)

by 本贾尼 斯特劳斯特鲁普
August 2021
Intermediate to advanced
450 pages
9h 36m
Chinese
Pearson
Content preview from C++程序设计:原理与实践(基础篇)(原书第2版)

11.1 有规律的与无规律的输入和输出

iostream库,也就是ISO C++标准库的输入输出部分,为文本输入输出提供了一个统一的、可扩展的框架。这里的“文本”指的是任何可以表示为字符序列的数据。这样,当我们讨论输入输出时,可以将1234这样的整数也看作文本,因为它可以写成4个字符1、2、3、4。

到目前为止,我们对所有的输入源都是以相同方式处理的。但有时这是不够的,例如,有些文件可能与其他输入源不同(如通信连接),在其中我们可以定位单个字节。类似地,我们还假定输入输出格式完全由对象类型所决定。这是不完全正确的,某些情况下也是不够的。例如,我们常常会指定浮点数输出的数字个数(精度)。本章将介绍一些方法,使我们可以按需求定制输入输出。

作为程序员,我们更喜欢有规律的编程,如一致地处理所有内存对象、以相同方式处理所有输入源、强制使用单一标准对进入和离开系统的对象进行表示,从而写出干净、简单、易于维护而且通常更高效的代码。但是,程序的存在是为了服务于人类,而人类都有自己强烈的偏好。因此,作为程序员,我们必须力争在程序复杂性和满足用户个人偏好间达到平衡。

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

C++语言导学(原书第2版)

C++语言导学(原书第2版)

本贾尼 斯特劳斯特鲁普
管理Kubernetes

管理Kubernetes

Brendan Burns, Craig Tracey
Python编程入门与实战

Python编程入门与实战

Posts & Telecom Press, Fabrizio Romano

Publisher Resources

ISBN: 9787111562252