100% found this document useful (9 votes)
462 views

Instant Download (Ebook) Programming: Principles and Practice Using C++, Third Edition by Bjarne Stroustrup PDF All Chapters

The document promotes the ebook 'Programming: Principles and Practice Using C++, Third Edition' by Bjarne Stroustrup, available for download in various formats. It outlines the book's content, which aims to teach programming principles and skills using C++, catering to both beginners and those with some programming knowledge. Additionally, it provides links to other related ebooks by the same author.

Uploaded by

lumpelaizer
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (9 votes)
462 views

Instant Download (Ebook) Programming: Principles and Practice Using C++, Third Edition by Bjarne Stroustrup PDF All Chapters

The document promotes the ebook 'Programming: Principles and Practice Using C++, Third Edition' by Bjarne Stroustrup, available for download in various formats. It outlines the book's content, which aims to teach programming principles and skills using C++, catering to both beginners and those with some programming knowledge. Additionally, it provides links to other related ebooks by the same author.

Uploaded by

lumpelaizer
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 65

Download Full Version ebook - Visit ebooknice.

com

(Ebook) Programming: Principles and Practice Using


C++, Third Edition by Bjarne Stroustrup

https://ebooknice.com/product/programming-principles-and-
practice-using-c-third-edition-56321970

Click the button below to download

DOWLOAD EBOOK

Discover More Ebook - Explore Now at ebooknice.com


Instant digital products (PDF, ePub, MOBI) ready for you
Download now and discover formats that fit your needs...

Start reading on any device today!

(Ebook) Programming: Principles and Practice Using C++ by


Bjarne Stroustrup ISBN 9780321543721, 0321543726

https://ebooknice.com/product/programming-principles-and-practice-
using-c-2424916

ebooknice.com

(Ebook) Programming: Principles and Practice Using C++ by


Stroustrup, Bjarne ISBN 9780138308681, 0138308683

https://ebooknice.com/product/programming-principles-and-practice-
using-c-56327430

ebooknice.com

(Ebook) Programming: Principles and Practice Using C++ ,


Second Edition by Stroustrup, Bjarne ISBN 9780321992789,
9780897919609, 0321992784, 0897919602
https://ebooknice.com/product/programming-principles-and-practice-
using-c-second-edition-10314450

ebooknice.com

(Ebook) Programming: Principles and Practices using C++ by


Bjarne Stroustrup ISBN 9780321992789, 0321992784,
2014004197
https://ebooknice.com/product/programming-principles-and-practices-
using-c-24406320

ebooknice.com
(Ebook) A Tour of C++ by Stroustrup, Bjarne ISBN
9780134998053, 0134998057

https://ebooknice.com/product/a-tour-of-c-12027654

ebooknice.com

(Ebook) Tour of C++, A (C++ In-Depth Series) by


Stroustrup, Bjarne ISBN 9780136816485, 0136816487

https://ebooknice.com/product/tour-of-c-a-c-in-depth-series-55560318

ebooknice.com

(Ebook) A Tour of C++ by Stroustrup, Bjarne ISBN


9780134997834, 9780134998053, 0134997832, 0134998057

https://ebooknice.com/product/a-tour-of-c-12027658

ebooknice.com

(Ebook) Smart Grammar and Vocabulary: Split edition 2B


Student's Book by H. Q. Mitchell ISBN 9789604434497,
9604434497
https://ebooknice.com/product/smart-grammar-and-vocabulary-split-
edition-2b-student-s-book-23340516

ebooknice.com

(Ebook) Primary Mathematics Workbook 2B by Jennifer Hoerst


ISBN 9780761469933, 0761469931

https://ebooknice.com/product/primary-mathematics-workbook-2b-23520620

ebooknice.com
About This eBook
ePUB is an open, industry-standard format for eBooks. However,
support of ePUB and its many features varies across reading devices
and applications. Use your device or app settings to customize the
presentation to your liking. Settings that you can customize often
include font, font size, single or double column, landscape or portrait
mode, and figures that you can click or tap to enlarge. For additional
information about the settings and features on your reading device
or app, visit the device manufacturer’s Web site.
Many titles include programming code or configuration examples.
To optimize the presentation of these elements, view the eBook in
single-column, landscape mode and adjust the font size to the
smallest setting. In addition to presenting code and configurations in
the reflowable text format, we have included images of the code
that mimic the presentation found in the print book; therefore,
where the reflowable format may compromise the presentation of
the code listing, you will see a “Click here to view code image” link.
Click the link to view the print-fidelity code image. To return to the
previous page viewed, click the Back button on your device or app.
Programming: Principles and
Practice Using C++

Third Edition

Bjarne Stroustrup

Hoboken, New Jersey


Cover photo by Photowood Inc./Corbis.
Author photo courtesy of Bjarne Stroustrup.
Page 294: “Promenade a Skagen” by Peder Severin Kroyer.
Page 308: Photo of NASA’s Ingenuity Mars Helicopter, The National
Aeronautics and Space Administration (NASA).
Page 354: Photo of Hurricane Rita as seen from space, The National
Oceanic and Atmospheric Administration (NOAA).

Many of the designations used by manufacturers and sellers to


distinguish their products are claimed as trademarks. Where those
designations appear in this book, and the publisher was aware of a
trademark claim, the designations have been printed with initial
capital letters or in all capitals.

The author and publisher have taken care in the preparation of this
book, but make no expressed or implied warranty of any kind and
assume no responsibility for errors or omissions. No liability is
assumed for incidental or consequential damages in connection with
or arising out of the use of the information or programs contained
herein.

For information about buying this title in bulk quantities, or for


special sales opportunities (which may include electronic versions;
custom cover designs; and content particular to your business,
training goals, marketing focus, or branding interests), please
contact our corporate sales department at
[email protected] or (800) 382-3419.

For government sales inquiries, please contact


[email protected].
For questions about sales outside the U.S., please contact
[email protected].

Visit us on the Web: informit.com/aw

Library of Congress Control Number: 2024932369

Copyright 2024 by Pearson Education, Inc.

All rights reserved. This publication is protected by copyright, and


permission must be obtained from the publisher prior to any
prohibited reproduction, storage in a retrieval system, or
transmission in any form or by any means, electronic, mechanical,
photocopying, recording, or likewise. For information regarding
permissions, request forms and the appropriate contacts within the
Pearson Education Global Rights & Permissions Department, please
visit www.pearson.com/permissions.

This book was typeset in Times and Helvetica by the author.

ISBN-13: 978-0-13-830868-1
ISBN-10: 0-13-83086-3
First printing, May 2024
$PrintCode
Contents

Preface

0 Notes to the Reader


0.1 The structure of this book
0.2 A philosophy of teaching and learning
0.3 ISO standard C++
0.4 PPP support
0.5 Author biography
0.6 Bibliography

Part I: The Basics

1 Hello, World!
1.1 Programs
1.2 The classic first program
1.3 Compilation
1.4 Linking
1.5 Programming environments

2 Objects, Types, and Values


2.1 Input
2.2 Variables
2.3 Input and type
2.4 Operations and operators
2.5 Assignment and initialization
2.6 Names
2.7 Types and objects
2.8 Type safety
2.9 Conversions
2.10 Type deduction: auto

3 Computation
3.1 Computation
3.2 Objectives and tools
3.3 Expressions
3.4 Statements
3.5 Functions
3.6 vector
3.7 Language features

4 Errors!
4.1 Introduction
4.2 Sources of errors
4.3 Compile-time errors
4.4 Link-time errors
4.5 Run-time errors
4.6 Exceptions
4.7 Avoiding and finding errors

5 Writing a Program
5.1 A problem
5.2 Thinking about the problem
5.3 Back to the calculator!
5.4 Back to the drawing board
5.5 Turning a grammar into code
5.6 Trying the first version
5.7 Trying the second version
5.8 Token streams
5.9 Program structure

6 Completing a Program
6.1 Introduction
6.2 Input and output
6.3 Error handling
6.4 Negative numbers
6.5 Remainder: %
6.6 Cleaning up the code
6.7 Recovering from errors
6.8 Variables

7 Technicalities: Functions, etc.


7.1 Technicalities
7.2 Declarations and definitions
7.3 Scope
7.4 Function call and return
7.5 Order of evaluation
7.6 Namespaces
7.7 Modules and headers

8 Technicalities: Classes, etc.


8.1 User-defined types
8.2 Classes and members
8.3 Interface and implementation
8.4 Evolving a class: Date
8.5 Enumerations
8.6 Operator overloading
8.7 Class interfaces

Part II: Input and Output

9 Input and Output Streams


9.1 Input and output
9.2 The I/O stream model
9.3 Files
9.4 I/O error handling
9.5 Reading a single value
9.6 User-defined output operators
9.7 User-defined input operators
9.8 A standard input loop
9.9 Reading a structured file
9.10 Formatting
9.11 String streams

10 A Display Model
10.1 Why graphics?
10.2 A display model
10.3 A first example
10.4 Using a GUI library
10.5 Coordinates
10.6 Shapes
10.7 Using Shape primitives
10.8 Getting the first example to run

11 Graphics Classes
11.1 Overview of graphics classes
11.2 Point and Line
11.3 Lines
11.4 Color
11.5 Line_style
11.6 Polylines
11.7 Closed shapes
11.8 Text
11.9 Mark
11.10 Image

12 Class Design
12.1 Design principles
12.2 Shape
12.3 Base and derived classes
12.4 Other Shape functions
12.5 Benefits of object-oriented programming

13 Graphing Functions and Data


13.1 Introduction
13.2 Graphing simple functions
13.3 Function
13.4 Axis
13.5 Approximation
13.6 Graphing data

14 Graphical User Interfaces


14.1 User-interface alternatives
14.2 The “Next” button
14.3 A simple window
14.4 Button and other Widgets
14.5 An example: drawing lines
14.6 Simple animation
14.7 Debugging GUI code

Part III: Data and Algorithms

15 Vector and Free Store


15.1 Introduction
15.2 vector basics
15.3 Memory, addresses, and pointers
15.4 Free store and pointers
15.5 Destructors
15.6 Access to elements
15.7 An example: lists
15.8 The this pointer

16 Arrays, Pointers, and References


16.1 Arrays
16.2 Pointers and references
16.3 C-style strings
16.4 Alternatives to pointer use
16.5 An example: palindromes

17 Essential Operations
17.1 Introduction
17.2 Access to elements
17.3 List initialization
17.4 Copying and moving
17.5 Essential operations
17.6 Other useful operations
17.7 Remaining Vector problems
17.8 Changing size
17.9 Our Vector so far
18 Templates and Exceptions
18.1 Templates
18.2 Generalizing Vector
18.3 Range checking and exceptions
18.4 Resources and exceptions
18.5 Resource-management pointers

19 Containers and Iterators


19.1 Storing and processing data
19.2 Sequences and iterators
19.3 Linked lists
19.4 Generalizing Vector yet again
19.5 An example: a simple text editor
19.6 vector, list, and string

20 Maps and Sets


20.1 Associative containers
20.2 map
20.3 unordered_map
20.4 Timing
20.5 set
20.6 Container overview
20.7 Ranges and iterators

21 Algorithms
21.1 Standard-library algorithms
21.2 Function objects
21.3 Numerical algorithms
21.4 Copying
21.5 Sorting and searching
Index
Preface

Damn the
torpedoes!
Full speed ahead.
– Admiral
Farragut

Programming is the art of expressing solutions to problems so that a


computer can execute those solutions. Much of the effort in
programming is spent finding and refining solutions. Often, a
problem is only fully understood through the process of
programming a solution for it.
This book is for someone who has never programmed before but
is willing to work hard to learn. It helps you understand the
principles and acquire the practical skills of programming using the
C++ programming language. It can also be used by someone with
some programming knowledge who wants a more thorough
grounding in programming principles and contemporary C++.
Why would you want to program? Our civilization runs on
software. Without understanding software, you are reduced to
believing in “magic” and will be locked out of many of the most
interesting, profitable, and socially useful technical fields of work.
When I talk about programming, I think of the whole spectrum of
computer programs from personal computer applications with GUIs
(graphical user interfaces), through engineering calculations and
embedded systems control applications (such as digital cameras,
cars, and cell phones), to text manipulation applications as found in
many humanities and business applications. Like mathematics,
programming – when done well – is a valuable intellectual exercise
that sharpens our ability to think. However, thanks to feedback from
the computer, programming is more concrete than most forms of
math and therefore accessible to more people. It is a way to reach
out and change the world – ideally for the better. Finally,
programming can be great fun.
There are many kinds of programming. This book aims to serve
those who want to write nontrivial programs for the use of others
and to do so responsibly, providing a decent level of system quality.
That is, I assume that you want to achieve a level of
professionalism. Consequently, I chose the topics for this book to
cover what is needed to get started with real-world programming,
not just what is easy to teach and learn. If you need a technique to
get basic work done right, I describe it, demonstrate concepts and
language facilities needed to support the technique, and provide
exercises for it. If you just want to understand toy programs or write
programs that just call code provided by others, you can get along
with far less than I present. In such cases, you will probably also be
better served by a language that’s simpler than C++. On the other
hand, I won’t waste your time with material of marginal practical
importance. If an idea is explained here, it’s because you’ll almost
certainly need it.
Programming is learned by writing programs. In this,
programming is similar to other endeavors with a practical
component. You cannot learn to swim, to play a musical instrument,
or to drive a car just from reading a book – you must practice. Nor
can you become a good programmer without reading and writing
lots of code. This book focuses on code examples closely tied to
explanatory text and diagrams. You need those to understand the
ideals, concepts, and principles of programming and to master the
language constructs used to express them. That’s essential, but by
itself, it will not give you the practical skills of programming. For
that, you need to do the exercises and get used to the tools for
writing, compiling, and running programs. You need to make your
own mistakes and learn to correct them. There is no substitute for
writing code. Besides, that’s where the fun is!
There is more to programming – much more – than following a
few rules and reading the manual. This book is not focused on “the
syntax of C++.” C++ is used to illustrate fundamental concepts.
Understanding the fundamental ideals, principles, and techniques is
the essence of a good programmer. Also, “the fundamentals” are
what last: they will still be essential long after today’s programming
languages and tools have evolved or been replaced.
Code can be beautiful as well as useful. This book is written to
help you to understand what it means for code to be beautiful, to
help you to master the principles of creating such code, and to build
up the practical skills to create it. Good luck with programming!

Previous Editions
The third edition of Programming: Principles and Practice Using C++
is about half the size of the second edition. Students having to carry
the book will appreciate the lighter weight. The reason for the
reduced size is simply that more information about C++ and its
standard library is available on the Web. The essence of the book
that is generally used in a course in programming is in this third
edition (“PPP3”), updated to C++20 plus a bit of C++23. The fourth
part of the previous edition (“PPP2”) was designed to provide extra
information for students to look up when needed and is available on
the Web:

Chapter 1: Computers, People, and Programming


Chapter 11: Customizing Input and Output
Chapter 22: Ideas and History
Chapter 23 Text Manipulation
Chapter 24: Numerics
Chapter 25: Embedded Systems Programming
Chapter 26: Testing
Chapter 27: The C Programming Language
Glossary

Where I felt it useful to reference these chapters, the references


look like this: PPP2.Ch22 or PPP2.§27.1.

Acknowledgments
Special thanks to the people who reviewed drafts of this book and
suggested many improvements: Clovis L. Tondo, Jose Daniel Garcia
Sanchez, J.C. van Winkel, and Ville Voutilainen. Also, Ville Voutilainen
did the non-trivial mapping of the GUI/Graphics interface library to
Qt, making it portable to an amazing range of systems.
Also, thanks to the many people who contributed to the first and
second editions of this book. Many of their comments are reflected
in this third edition.
0

Notes to the Reader

eiπ + 1
– Leonhard Euler

This chapter is a grab bag of information; it aims to give you an idea of


what to expect from the rest of the book. Please skim through it and read
what you find interesting. Before writing any code, read “PPP support”
(§0.4). A teacher will find most parts immediately useful. If you are
reading this book as a novice, please don’t try to understand everything.
You may want to return and reread this chapter once you feel comfortable
writing and executing small programs.

§0.1 The structure of this book


General approach; Drills, exercises, etc.; What comes after this book?
§0.2 A philosophy of teaching and learning
A note to students; A note to teachers
§0.3 ISO standard C++
Portability; Guarantees; A brief history of C++
§0.4 PPP support
Web resources
§0.5 Author biography
§0.6 Bibliography

0.1 The structure of this book


This book consists of three parts:

Part I (Chapter 1 to Chapter 8) presents the fundamental concepts and


techniques of programming together with the C++ language and library
facilities needed to get started writing code. This includes the type system,
arithmetic operations, control structures, error handling, and the design,
implementation, and use of functions and user-defined types.
Part II (Chapter 9 to Chapter 14) first describes how to get numeric and text
data from the keyboard and from files, and how to produce corresponding
output to the screen and to files. Then, we show how to present numeric data,
text, and geometric shapes as graphical output, and how to get input into a
program from a graphical user interface (GUI). As part of that, we introduce
the fundamental principles and techniques of object-oriented programming.
Part III (Chapter 15 to Chapter 21) focuses on the C++ standard library’s
containers and algorithms framework (often referred to as the STL). We show
how containers (such as vector, list, and map) are implemented and used. In
doing so, we introduce low-level facilities such as pointers, arrays, and dynamic
memory. We also show how to handle errors using exceptions and how to
parameterize our classes and functions using templates. As part of that, we
introduce the fundamental principles and techniques of generic programming.
We also demonstrate the design and use of standard-library algorithms (such
as sort, find, and inner_product).

The order of topics is determined by programming techniques, rather than


programming language features.

CC
To ease review and to help you if you miss a key point during a first reading
where you have yet to discover which kind of information is crucial, we place three
kinds of “alert markers” in the margin:

CC: concepts and techniques (this paragraph is an example of that)


AA: advice
XX: warning
The use of CC, AA, and XX, rather than a single token in different colors, is to help
where colors are not easy to distinguish.

0.1.1 General approach


In this book, we address you directly. That is simpler and clearer than the
conventional “professional” indirect form of address, as found in most scientific
papers. By “you” we mean “you, the reader,” and by “we” we mean “you, the
author, and teachers,” working together through a problem, as we might have done
had we been in the same room. I use "I" when I refer to my own work or personal
opinions.

AA
This book is designed to be read chapter by chapter from the beginning to the
end. Often, you’ll want to go back to look at something a second or a third time. In
fact, that’s the only sensible approach, as you’ll always dash past some details that
you don’t yet see the point in. In such cases, you’ll eventually go back again.
Despite the index and the cross-references, this is not a book that you can open to
any page and start reading with any expectation of success. Each section and each
chapter assume understanding of what came before.
Each chapter is a reasonably self-contained unit, meant to be read in “one
sitting” (logically, if not always feasible on a student’s tight schedule). That’s one
major criterion for separating the text into chapters. Other criteria include that a
chapter is a suitable unit for drills and exercises and that each chapter presents
some specific concept, idea, or technique. This plurality of criteria has left a few
chapters uncomfortably long, so please don’t take “in one sitting” too literally. In
particular, once you have thought about the review questions, done the drill, and
worked on a few exercises, you’ll often find that you have to go back to reread a
few sections.
A common praise for a textbook is “It answered all my questions just as I
thought of them!” That’s an ideal for minor technical questions, and early readers
have observed the phenomenon with this book. However, that cannot be the whole
ideal. We raise questions that a novice would probably not think of. We aim to ask
and answer questions that you need to consider when writing quality software for
the use of others. Learning to ask the right (often hard) questions is an essential
part of learning to think as a programmer. Asking only the easy and obvious
questions would make you feel good, but it wouldn’t help make you a programmer.
We try to respect your intelligence and to be considerate about your time. In our
presentation, we aim for professionalism rather than cuteness, and we’d rather
understate a point than hype it. We try not to exaggerate the importance of a
programming technique or a language feature, but please don’t underestimate a
simple statement like “This is often useful.” If we quietly emphasize that something
is important, we mean that you’ll sooner or later waste days if you don’t master it.
Our use of humor is more limited than we would have preferred, but experience
shows that people’s ideas of what is funny differ dramatically and that a failed
attempt at humor can be confusing.

CC
We do not pretend that our ideas or the tools offered are perfect. No tool, library,
language, or technique is “the solution” to all of the many challenges facing a
programmer. At best, a language can help you to develop and express your solution.
We try hard to avoid “white lies”; that is, we refrain from oversimplified
explanations that are clear and easy to understand, but not true in the context of
real languages and real problems.

0.1.2 Drills, exercises, etc


AA
Programming is not just an intellectual activity, so writing programs is necessary to
master programming skills. We provide three levels of programming practice:

Drills: A drill is a very simple exercise devised to develop practical, almost


mechanical skills. A drill usually consists of a sequence of modifications of a
single program. You should do every drill. A drill is not asking for deep
understanding, cleverness, or initiative. We consider the drills part of the basic
fabric of the book. If you haven’t done the drills, you have not “done” the book.
Exercises: Some exercises are trivial, and others are very hard, but most are
intended to leave some scope for initiative and imagination. If you are serious,
you’ll do quite a few exercises. At least do enough to know which are difficult
for you. Then do a few more of those. That’s how you’ll learn the most. The
exercises are meant to be manageable without exceptional cleverness, rather
than to be tricky puzzles. However, we hope that we have provided exercises
that are hard enough to challenge anybody and enough exercises to exhaust
even the best student’s available time. We do not expect you to do them all,
but feel free to try.
Try this: Some people like to put the book aside and try some examples before
reading to the end of a chapter; others prefer to read ahead to the end before
trying to get code to run. To support readers with the former preference, we
provide simple suggestions for practical work labeled Try this at natural breaks
in the text. A Try this is generally in the nature of a drill but focused narrowly
on the topic that precedes it. If you pass a Try this without trying it out –
maybe because you are not near a computer or you find the text riveting – do
return to it when you do the chapter drill; a Try this either complements the
chapter drill or is a part of it.

In addition, at the end of each chapter we offer some help to solidify what’s
learned:

Review: At the end of each chapter, you’ll find a set of review questions. They
are intended to point you to the key ideas explained in the chapter. One way to
look at the review questions is as a complement to the exercises: the exercises
focus on the practical aspects of programming, whereas the review questions
try to help you articulate the ideas and concepts. In that, they resemble good
interview questions.
Terms: A section at the end of each chapter presents the basic vocabulary of
programming and of C++. If you want to understand what people say about
programming topics and to articulate your own ideas, you should know what
each term means.
Postscript: A paragraph intended to provide some perspective for the material
presented.

In addition, we recommend that you take part in a small project (and more if time
allows for it). A project is intended to produce a complete useful program. Ideally, a
project is done by a small group of people (e.g., three people) working together
(e.g., while progressing through the later chapters of the book). Most people find
such projects the most fun and that they tie everything together.

CC
Learning involves repetition. Our ideal is to make every important point at least
twice and to reinforce it with exercises.

0.1.3 What comes after this book?


AA
At the end of this book, will you be an expert at programming and at C++? Of
course not! When done well, programming is a subtle, deep, and highly skilled art
building on a variety of technical skills. You should no more expect to become an
expert at programming in four months than you should expect to become an expert
in biology, in math, in a natural language (such as Chinese, English, or Danish), or
at playing the violin in four months – or in half a year, or a year. What you should
hope for, and what you can expect if you approach this book seriously, is to have a
really good start that allows you to write relatively simple useful programs, to be
able to read more complex programs, and to have a good conceptual and practical
background for further work.
The best follow-up to this initial course is to work on a project developing code
to be used by someone else; preferably guided by an experienced developer. After
that, or (even better) in parallel with a project, read either a professional-level
general textbook, a more specialized book relating to the needs of your project, or a
textbook focusing on a particular aspect of C++ (such as algorithms, graphics,
scientific computation, finance, or games); see §0.6.

AA
Eventually, you should learn another programming language. We don’t consider
it possible to be a professional in the realm of software – even if you are not
primarily a programmer – without knowing more than one language. Why? No large
program is written in a single language. Also, different languages typically differ in
the way code is thought about and programs are constructed. Design techniques,
availability of libraries, and the way programs are built differ, sometimes
dramatically. Even when the syntaxes of two languages are similar, the similarity is
typically only skin deep. Performance, detection of errors, and constraints on what
can be expressed typically differ. This is similar to the ways natural languages and
cultures differ. Knowing only a single language and a single culture implies the
danger of thinking that “the way we do things” is the only way or the only good
way. That way opportunities are missed, and sub-optimal programs are produced.
One of the best ways to avoid such problems is to know several languages
(programming languages and natural languages).

0.2 A philosophy of teaching and learning


What are we trying to help you learn? And how are we approaching the process of
teaching? We try to present the minimal concepts, techniques, and tools for you to
do effective practical programs, including

Program organization
Debugging and testing
Class design
Computation
Function and algorithm design
Graphics (two-dimensional only)
Graphical user interfaces (GUIs)
Files and stream input and output (I/O)
Memory management
Design and programming ideals
The C++ standard library
Software development strategies

To keep the book lighter than the small laptop on which it is written, some
supplementary topics from the second edition are placed on the Web (§0.4.1):

Computers, People, and Programming (PPP2.Ch1)


Ideals and History (PPP2.Ch22)
Text manipulation (incl. Regular expression matching) (PPP2.Ch23)
Numerics (PPP2.Ch24)
Embedded systems programming (PPP2.Ch25)
C-language programming techniques (PPP2.Ch27)

Working our way through the chapters, we cover the programming techniques
called procedural programming (as with the C programming language), data
abstraction, object-oriented programming, and generic programming. The main
topic of this book is programming, that is, the ideals, techniques, and tools of
expressing ideas in code. The C++ programming language is our main tool, so we
describe many of C++’s facilities in some detail. But please remember that C++ is
just a tool, rather than the main topic of this book. This is “programming using
C++,” not “C++ with a bit of programming theory.”
Each topic we address serves at least two purposes: it presents a technique,
concept, or principle and also a practical language or library feature. For example,
we use the interface to a two-dimensional graphics system to illustrate the use of
classes and inheritance. This allows us to be economical with space (and your time)
and also to emphasize that programming is more than simply slinging code together
to get a result as quickly as possible. The C++ standard library is a major source of
such “double duty” examples – many even do triple duty. For example, we introduce
the standard-library vector, use it to illustrate widely useful design techniques, and
show many of the programming techniques used to implement it. One of our aims
is to show you how major library facilities are implemented and how they map to
hardware. We insist that craftsmen must understand their tools, not just consider
them “magical.”
Some topics will be of greater interest to some programmers than to others.
However, we encourage you not to prejudge your needs (how would you know what
you’ll need in the future?) and at least look at every chapter. If you read this book
as part of a course, your teacher will guide your selection.
CC
We characterize our approach as “depth-first.” It is also “concrete-first” and
“concept-based.” First, we quickly (well, relatively quickly, Chapter 1 to Chapter 9)
assemble a set of skills needed for writing small practical programs. In doing so, we
present a lot of tools and techniques in minimal detail. We focus on simple concrete
code examples because people grasp the concrete faster than the abstract. That’s
simply the way most humans learn. At this initial stage, you should not expect to
understand every little detail. In particular, you’ll find that trying something slightly
different from what just worked can have “mysterious” effects. Do try, though!
Please do the drills and exercises we provide. Just remember that early on you just
don’t have the concepts and skills to accurately estimate what’s simple and what’s
complicated; expect surprises and learn from them.

AA
We move fast in this initial phase – we want to get you to the point where you
can write interesting programs as fast as possible. Someone will argue, “We must
move slowly and carefully; we must walk before we can run!” But have you ever
watched a baby learning to walk? Babies really do run by themselves before they
learn the finer skills of slow, controlled walking. Similarly, you will dash ahead,
occasionally stumbling, to get a feel of programming before slowing down to gain
the necessary finer control and understanding. You must run before you can walk!

XX
It is essential that you don’t get stuck in an attempt to learn “everything” about
some language detail or technique. For example, you could memorize all of C++’s
built-in types and all the rules for their use. Of course you could, and doing so
might make you feel knowledgeable. However, it would not make you a
programmer. Skipping details will get you “burned” occasionally for lack of
knowledge, but it is the fastest way to gain the perspective needed to write good
programs. Note that our approach is essentially the one used by children learning
their native language and also the most effective approach used to learn a foreign
language. We encourage you to seek help from teachers, friends, colleagues,
Mentors, etc. on the inevitable occasions when you are stuck. Be assured that
nothing in these early chapters is fundamentally difficult. However, much will be
unfamiliar and might therefore feel difficult at first.
Later, we build on your initial skills to broaden your base of knowledge. We use
examples and exercises to solidify your understanding, and to provide a conceptual
base for programming.

AA
We place a heavy emphasis on ideals and reasons. You need ideals to guide you
when you look for practical solutions – to know when a solution is good and
principled. You need to understand the reasons behind those ideals to understand
why they should be your ideals, why aiming for them will help you and the users of
your code. Nobody should be satisfied with “because that’s the way it is” as an
explanation. More importantly, an understanding of ideals and reasons allows you to
generalize from what you know to new situations and to combine ideas and tools in
novel ways to address new problems. Knowing “why” is an essential part of
acquiring programming skills. Conversely, just memorizing lots of poorly understood
rules is limiting, a source of errors, and a massive waste of time. We consider your
time precious and try not to waste it.
Many C++ language-technical details are banished to other sources, mostly on
the Web (§0.4.1). We assume that you have the initiative to search out information
when needed. Use the index and the table of contents. Don’t forget the online help
facilities of your compiler. Remember, though, to consider every Web resource
highly suspect until you have reason to believe better of it. Many an authoritative-
looking Web site is put up by a programming novice or someone with something to
sell. Others are simply outdated. We provide a collection of links and information on
our support Web site: www.stroustrup.com/programming.xhtml.
Please don’t be too impatient for “realistic” examples. Our ideal example is the
shortest and simplest code that directly illustrates a language facility, a concept, or
a technique. Most real-world examples are far messier than ours, yet do not consist
of more than a combination of what we demonstrate. Successful commercial
programs with hundreds of thousands of lines of code are based on techniques that
we illustrate in a dozen 50-line programs. The fastest way to understand real-world
code is through a good understanding of the fundamentals.
We do not use “cute examples involving cuddly animals” to illustrate our points.
We assume that you aim to write real programs to be used by real people, so every
example that is not presented as specifically language-technical is taken from a
real-world use. Our basic tone is that of professionals addressing (future)
professionals.
C++ rests on two pillars:

Efficient direct access to machine resources: making C++ effective for low-
level, machine-near, programming as is essential in many application domains.
Powerful (Zero-overhead) abstraction mechanisms: making it possible to
escape the error-prone low-level programming by providing elegant, flexible,
and type-and-resource-safe, yet efficient facilities needed for higher-level
programming.

This book teaches both levels. We use the implementation of higher-level


abstractions as our primary examples to introduce low-level language features and
programming techniques. The aim is always to write code at the highest level
affordable, but that often requires a foundation built using lower-level facilities and
techniques. We aim for you to master both levels.

0.2.1 A note to students


AA
Many thousands of first-year university students taught using the first two editions
of this book had never before seen a line of code in their lives. Most succeeded, so
you can do it, too.
You don’t have to read this book as part of a course. The book is widely used for
self-study. However, whether you work your way through as part of a course or
independently, try to work with others. Programming has an – unfair – reputation as
a lonely activity. Most people work better and learn faster when they are part of a
group with a common aim. Learning together and discussing problems with friends
is not cheating! It is the most efficient – as well as most pleasant – way of making
progress. If nothing else, working with friends forces you to articulate your ideas,
which is just about the most efficient way of testing your understanding and making
sure you remember. You don’t actually have to personally discover the answer to
every obscure language and programming environment problem. However, please
don’t cheat yourself by not doing the drills and a fair number of exercises (even if
no teacher forces you to do them). Remember: programming is (among other
things) a practical skill that you must practice to master.
Most students – especially thoughtful good students – face times when they
wonder whether their hard work is worthwhile. When (not if) this happens to you,
take a break, reread this chapter, look at the “Computers, People, and
Programming” and “Ideals and History” chapters posted on the Web (§0.4.1).
There, I try to articulate what I find exciting about programming and why I consider
it a crucial tool for making a positive contribution to the world.
Please don’t be too impatient. Learning any major new and valuable skill takes
time.
The primary aim of this book is to help you to express your ideas in code, not to
teach you how to get those ideas. Along the way, we give many examples of how
we can address a problem, usually through analysis of a problem followed by
gradual refinement of a solution. We consider programming itself a form of problem
solving: only through complete understanding of a problem and its solution can you
express a correct program for it, and only through constructing and testing a
program can you be certain that your understanding is complete. Thus,
programming is inherently part of an effort to gain understanding. However, we aim
to demonstrate this through examples, rather than through “preaching” or
presentation of detailed prescriptions for problem solving.
Random documents with unrelated
content Scribd suggests to you:
"I don't deserve it. I'm a scoundrel, for with every thought of my
heart, with every breath I draw, I'm making love to another man's
wife!"
"You mustn't do it!"
He laughed, and his laugh was so strange that it startled them both.
"Your advice is good; I can't follow it, that's all. Rachel, for God's
sake, tell me the truth: do you love Belhaven, did you marry him of
your own free will?"
Rachel turned from him and went to the fireplace; she folded her
arms and laid her head upon them. She did not remember that
Belhaven had stood there on the day of their marriage. She was
cruelly placed; her love for Charter seemed to be the only thing in
the world. What real claim had Belhaven upon her? He had deceived
her, he had traded upon her loyalty to her sister, he had accepted
her sacrifice, he was only her husband in name. But what if she told
Charter the truth? He was good, but if she told him the truth? She
loved him with all her soul.
"I don't believe you love him," he argued; "you're wretched, I can
see it. I believe these hideous stories. Rachel, I have a right to know
the truth, only the truth!"
She shuddered. The truth? Oh, God, how she longed to tell him the
truth; her heart leaped at the thought!
"I ask for nothing else; if you love him, if you married him of your
own free choice, tell me; it will help me, it will drive me away. I'm
asking for bread, Rachel, and you've given me a stone."
She was weeping now, for she dared not tell him the truth, she
dared not.
"Only the truth, Rachel!"
Her tears dried, they seemed burned into her eyes, and she pressed
her hands against her throat; she felt as if she must surely strangle
to death.
"Did you marry Belhaven of your own choice?" John asked again and
his voice cut her to the heart; it was not like him to force her into a
corner, but he was battling for life himself and this vivid revelation of
his love was an acute agony to her.
She raised her head; she did not look at him, and her voice was very
low as she replied, "Of my own choice!"
Charter turned from her and hid his face a moment in his hands,—
strong, muscular, expressive hands, they were like him.
There was an intense silence.
At last he went slowly to the door. "Forgive me, I've been a brute—
good-by."
But the limit of her endurance had been reached. "John," she cried,
"come back!"
He turned and faced her; he looked as he had looked at death in
battle. "It's no use, Rachel; thank you for telling me the truth."
"I didn't; I lied to you."
He uttered an inarticulate sound.
"I lied to you," said Rachel steadily; "now I'm going to tell you the
truth. It's wrong, but I shall do it; I shall tell you the whole truth. I
married Belhaven to shield my sister from Astry's anger. Astry
accused her and Belhaven, she begged me to save her from
disgrace. I yielded, I married him; I never loved him, I'm only his
wife in name."
"Good God, was there no one in the world to stop you? No one to
save you from such madness? Rachel, did you have no thought of
me?"
"I thought—" her voice broke a little; she steadied herself again,
"John, let it go—I married him."
"I couldn't let it go—Rachel, you knew I loved you?"
She shook her head sadly.
"You knew it, you must have known it!"
"No woman knows it until she's told."
"Is it possible that you married him thinking I didn't? What a fool I
was, what a dunce! If I had only written you! But, Rachel, there was
the cholera in the camp and I was with the poor fellows all the time.
I thought you knew I loved you, I only tormented myself because I
wasn't sure of you!"
"We were neither of us sure, it seems; it's our poor, stupid, little
tragedy, John; let it go—it's over."
"You love me?" he asked gravely.
"Yes."
They stood looking at each other. There was no light in either face,
no triumphant recognition of mutual feeling; to both the situation
was horrible. He understood perfectly her feelings; that the fact of
her marriage was unchanged, that it constituted an insuperable
barrier between them; but he could not be restrained.
"I can't stand this, Rachel. Your marriage is in fact no marriage.
Belhaven has no right to hold you to it; it must be broken, you shall
be free!"
"I can't; don't you see it?" She held out both hands with a pathetic
gesture. "Can't you see it? It would undo all I've done to save her."
"Do you think for a moment that I'll give you up for Eva?"
Her face quivered pitifully. She longed to give up, to let him take the
lead and sweep her on to liberty. Then her tortured soul rose again
to the struggle. "I knew you wouldn't give up; that's why I lied to
you just now. I never did before, John."
"Is it possible you want this to go on?"
"It must!"
"It can't and it shan't!" he cried hotly. "I'm human, I won't give you
up; you shan't be bound by such a miserable tie—the man was a
cowardly brute to let you shield him."
"I did it for Eva; I've betrayed her by telling you."
"Eva wasn't worth it," said John, in honest wrath. "No one is worth
it. Rachel, I won't endure it."
"We've got to endure it; I can't publicly disgrace my sister."
"You needn't; Belhaven can make the way easy,—he can and he
shall!"
She shook her head. "He won't."
"He must."
She still shook her head.
A light broke in on John. "He loves you!" he cried suddenly.
She blushed and her eyes filled with tears. "Yes."
He turned and walked to and fro, his white face set and hard. She
watched him, reading him, trembling for him, with that intuitive
knowledge of his strength and his weakness which is an instinct with
a woman who loves much.
He swung around suddenly and faced her. "And you?" he asked, with
great bitterness.
She met his eyes bravely; she tried to speak but it was too much.
John caught her in his arms. "You do love me still?" he cried
passionately.
"With all my heart!" she said, for one blind moment swept away,
and, yielding to her own grief and his rebellion, she clung to him.
Then she recalled herself, her heart struggled back to meet fate
again. "John, we must part now—I'd hoped to keep your friendship,
but we've lost even that—there was, after all, no middle course."
"Do you think I'll give you up now? This marriage is a mockery; it's
got to be annulled."
She looked up at him, struggling to be calm. "John, I've always
believed in you, I've always trusted you; I trust you now to help me
to do right. I'm weak; I'm broken down; you know it, you've felt it—
help me to be myself!"
"I can't, and it isn't right, it's an outrage; who ever heard of such a
thing? Eva has no right to your life, Belhaven has no right to you—
you're mine!"
"I'm not yours while I'm his wife," she said steadily, and she slipped
out of his arms and stood trembling.
"His wife!" John laughed bitterly. "You're not, you can't remain his
wife, loving me. I can't think that of you, Rachel!"
"Don't think it. I couldn't."
"And you call it right to keep up this sham? It's a lie, Rachel, a living
lie!"
She wrung her hands in a kind of agony. "John, I can't bear much
more; you'll have to leave me now. Give me a little time, I—I can't
bear it!"
"My darling, forgive me!"
"Don't, John," she sobbed, "don't kiss me again—I've got to give you
up."
"I won't give you up."
"I've no right to disgrace poor Eva, to disgrace Astry; he's had
enough to bear, and that's what it would cost. Can't you see it?"
"It needn't, but Belhaven must release you, I'll make him."
"John, I can't do it. I love you, let me believe in you."
"Have I got to suffer for Belhaven?"
She slipped down on her knees beside a chair, and burying her head
on her arms, gave way to her grief. The spiritual agony had given
birth to agony of the body and she wept bitterly. He tried to raise
her in his arms but she resisted, still weeping.
"Rachel, you'll make me kill Belhaven."
She looked up at that, her eyes still full of tears.
"John, I did it of my own free will. The man has suffered too; it's
cruel to him, I can't disgrace and ruin him now. I can't betray Eva, I
can't simply think of my own happiness; I'm not like that! I did it
myself. I thought you didn't care; I was angry, blind, and, yes, I did
want to save my sister, but I've often thought that perhaps I
wouldn't have done it but for my anger. I deserve to be punished,
and I've got to bear it somehow. What would be the use of it all if,
at the first temptation, I gave in and told the world the whole
miserable story? When mother was dying she made me promise to
be good to Eva; she said she might need all that I could give, she
knew her! I can't disgrace her. She's heart-broken about it all, she's
sorry; I think I can bring her back to her husband. It's worth trying,
John. I've always believed in you, I've always trusted you; help me
to be true to myself, help me—because you love me!"
"I can't give you up."
She turned away from him, struggling hard for more composure.
"Give me a little time, John. I—I can't bear any more now!"
"You mean you want me to go now? I'll do your bidding, Rachel, but
I'll never give you up; I can't."
"Oh, I know—I know, but go—please, John, I can't answer now—I
can't do wrong."
"I'm going—you see I'm not trying to force it; I won't even touch
you, but I won't give you up."
She did not answer, but stood with bowed head, the charm and
grace of her figure outlined against the soft, warm glow of the room,
her hands wrung together to hide their trembling. He turned at the
door and looked back at her and she tried to smile. There is
sometimes mortal agony behind a smile.
"Because I love you, John," she said, with a gesture of appeal.
He turned with a groan and went out into the night.
XVI
IT was nearly an hour later when Charter made his way to the
fashionable club that he knew Belhaven commonly frequented. He
went deliberately, after a brief space of time given to what he would
have called deliberation, but which did not deserve the name. He
had left Rachel in a storm of feeling, so much more violent than
anything usual to his equable nature that he had been unable at first
to think with coherence. All smaller considerations, even the events
of yesterday, seemed relegated to the limbo of eternal forgetfulness,
and nothing was of consequence but this terrible fact, thrust so
rudely into his life, this trapping of the woman he loved by a coward
who was using her, so Charter felt, as a shield to save him from the
punishment which he so richly deserved. Yet, even in his passion, he
saw that Rachel's argument was true, that he could do nothing
without exposing both sisters to an open scandal, but, in his present
mood, even that seemed a small matter compared to Rachel's
vindication, and he had no pity for Eva at all.
It was certain, however, that he could not apply primitive methods to
the case, and he did not even dream of wringing Belhaven's neck,
but, in spite of his rage against him, he was also aware that he could
not let this go on without informing him of his own position. When
he left the old house on the hill, he had felt keenly the sting of
shame and disgust. It seemed to him that he had been there on
Belhaven's own errand, to make love to another man's wife, that he
was falling to the level of his adversary. But he would not give
Rachel up; every instinct battled against such a renunciation, and,
being determined to rescue her at any cost, he suddenly hit upon
the only course that seemed open to one of his temperament. He
would see Belhaven and warn him; he would tell him, face to face,
exactly what he intended to do. This idea taking possession of him,
he acted upon it with a sudden deviation from his usual tardy
deliberation; he went directly to the club and inquired for Belhaven.
As he supposed, he had no difficulty in finding him, seated in a
corner of the library reading, or pretending to read, a new book that
in reality was only a cover to prevent the interruption of his thought,
for Belhaven had more than enough to occupy his mind.
Catching sight of his dark head and handsome profile bent over his
book in a remote corner of the big room, Charter walked in, and
observing that the only other occupants, two rather elderly men,
were deeply engaged with their newspapers, he went over to
Belhaven's retreat and addressed him with an abruptness that made
him start slightly and lay his book upon his knee.
"I want a word with you."
Belhaven's face darkened with the recollection of John's hands on
his throat but he restrained himself with admirable determination.
"I can't exactly prevent you from saying it here," he remarked coolly.
But John took no notice of his manner; instead he leaned against
the wall opposite and folded his arms across his breast, perhaps to
be certain that he would not make too violent use of them, but he
spoke as calmly as Belhaven had, only with a slight stiffening of the
lips that with him was a sign of great anger hardly controlled.
"I came over here to tell you that I've just been to your house; I
don't want you to think I'm a sneak or a coward. I went there to see
Mrs. Belhaven because I've heard—pretty plainly—all the
circumstances of your marriage."
Belhaven took up the pipe which he had laid down at John's
approach and held it thoughtfully between his fingers, looking into
the bowl of it.
"After what occurred the other day I suppose I needn't say I think
it's none of your business."
"That's just the point; it is. I love Mrs. Belhaven and I won't give her
up to you—after all I've found out!"
Belhaven threw back his head and their eyes met.
"Has she told you?"
Charter hesitated, his face flushing as darkly as his interrogator's. He
had not foreseen this natural question.
"I refuse to answer."
Belhaven smiled bitterly. "In other words you've been making love to
my wife."
"Exactly; that's what I want to say. I don't propose to be a sneak
about it; I love her and I won't allow her to be nothing more than a
shield to protect you from Astry."
Belhaven considered this a moment. His first impulse was to resent it
angrily, but, after a little thought, he decided to let it go
unquestioned. "Perhaps you don't know that she's determined to
protect Mrs. Astry."
"I don't consider that Mrs. Astry is worth her life."
"You think she's ruining her life to marry me?"
"You know well enough that you had no right to marry her!"
Belhaven's hand trembled slightly, but he emptied the ashes out of
his pipe before he replied.
"You're taking the natural view of a man in love with another man's
wife."
"That's neither here nor there; she's the one to consider. If you're a
man you'll simply give her her freedom. It's the least thing you can
do, the only reparation you can make."
"I don't suppose it occurs to you that, perhaps, she wouldn't take it."
"That's inconceivable."
"You don't know then that she has peculiar ideas about the
sacredness of the marriage ceremony?"
"Which couldn't apply to this case; you must see that yourself."
"You mean because she's married me? But I don't suppose I've
anything to do with a fixed principle."
"You think she'd apply her scruples even to such a mockery of
marriage as this?"
Belhaven assented grimly.
"You've no right to let her do it!"
"Has it occurred to you that I've a right to have my own feelings
about it?"
"You haven't; you've got to consider her, to give her up."
"And if I refuse?"
John's angry blue eyes glowed deeply. "Do you think that I'm going
to stand it? I'm a factor in this case."
Belhaven eyed him coldly. "Has she made you so?"
Charter winced; he felt keenly that Rachel had not. "No!" he said
sharply.
"Well, she won't. I know her well enough for that. You think you
know all about her because you're in love with her, but you don't if
you imagine she's like that; she—" he stopped and drew a deep
breath that was nearer pain than a sigh—"she's too fine for that! I
know her better than you do and if I choose to hold her to it I can;
she won't listen to you if she feels it to be wrong, and she will."
"And you mean to take advantage of her very goodness to keep her
to such a bargain?"
His scorn cut like a knife but Belhaven met it without self-betrayal.
"Why should I give her up to you?" he asked, after a moment.
Charter looked at him attentively. He remembered that Rachel had
admitted that Belhaven loved her and he began to suspect now that
he would never give her up, that he meant to use his claim upon her
to keep her against her will. Such an attitude was almost
inconceivable to John.
"You intend to make her stay because you've fallen in love with
her?"
"That's no affair of yours."
John glanced across at the old man opposite, who was hunting now
for another newspaper on the table. In the distance he saw Count
Massena coming through the corridor.
"I'm sorry that this is a place where I can't tell you just what I think
of you," he said.
Belhaven did not move. "I can't see that you're in a better situation
than I am," he retorted coolly. "You've no right to make love to my
wife."
"You've no right to make your wife endure this misery and I tell you
now I won't allow it."
Rachel's husband watched him thoughtfully, a drawn look changing
his face yet more deeply.
"See here, Charter," he said suddenly, "I'm willing to say this: I've
lived in the same house with Rachel long enough to be a changed
man. She's humanized me. I'm not quite what you think me, and I'll
let her decide in the end, but, by Jove, I won't give her up just for
you; I'd die first!"
John looked at him squarely. "If you're a man," he said again, "you'll
set her free; then she could choose. Now—if you hold her—"
"Well, and if I do?"
"Then," said John, "you're a damned scoundrel!" and he turned his
back on him and walked out of the room.
XVII
ASTRY was amusing himself driving the billiard balls about on the
table, practising some of his favorite strokes. He was an unusually
graceful man and he showed it as he handled his cue, his cigarette
between his teeth and his eyes narrowed in thought. He had long
ago ceased to be a happy man. There had been moments, years
before, when he had been considered rather jolly; men liked him
and women liked him too. He was greatly changed; the hardening
process had destroyed some of the more tender amenities of life.
He drove the ball successfully and stopped to chalk his cue; on the
wire over his head one of his parrots balanced, sidling along and
talking once and a while in strange jargon. Astry watched him, half
amused, then he continued to play with the balls. The house was
profoundly quiet; at the moment they had no house guests, though
Eva courted company for she dreaded being alone with her husband.
He had asked John Charter to come to them but John had refused.
The refusal did not surprise Astry; it only confirmed him in certain
suspicions and, as the balls danced away from his driving cue, he
was thinking of Rachel. Hers was undoubtedly the figure of the
drama and he knew that she was unhappy; he divined much more
though he made no sign. But he was as other men; he desired love,
he craved happiness, he had been embittered by the loss of both,
poisoned by the contact of treachery, and he had ceased to believe,
he had even ceased to forgive. Forgiveness is godlike, and very few
of us ever know it, feel it, or receive it. Forgiveness is like the work
in a stone quarry; it takes hard labor and only the morally great
accomplish it. But Astry saw revealed Rachel's love for Eva and the
sight of it was almost irritating; it seemed as if she wasted it, that
Eva gave back so little. He had come to think that Eva had very little
to give.
He continued to play with the balls. Presently the old clock in the hall
chimed sweetly, five o'clock. Then he heard his wife coming. She
had been out and had just returned; she came through the drawing-
room, her dress rustling, her light footstep uneven. He reached up
and, taking the chattering parrot from the wire, put him into the
conservatory and came back with his cue in his hand just as Eva
looked in.
"Playing billiards alone," she remarked languidly. "I should think it
would bore you to death."
"My dear Eva, I'm bored to extinction, but one must have something
to do."
She came slowly into the room and, going to the window, stood
there looking out.
"I suppose you'd really be happier if you weren't so rich," she
remarked.
"Do you think it's altogether a matter of money? That the possession
of it brings misery?"
"Sometimes I think it does. I don't seem to think of any one I know
who's very rich and happy too."
Astry put his cue down on the table and sat down; he seemed
willing to discuss the point. "Suppose you were poor to-morrow,
Eva; would you be any less wretched?"
She gave him a startled look over her shoulder. "Who said I was
wretched?"
He smiled grimly. "He who runs may read."
She drew a quick breath of alarm, pressing her cheek against the
window-pane and looking out with unseeing eyes. Before her was
the wide terrace, the level stretch of lawn with here and there a
mound of unmelted snow, and beyond the bare, brown trees and
the winter sky.
Astry spoke again with a certain moderation, a mental detachment
that made her feel how wide was the chasm between them.
"I can see you're unhappy and I'm sorry. I don't know that there's
much to do about it. Divorce is common but a little vulgar. I'm not
sure that you care to have me offer you such an avenue of escape."
"I must have been very unpleasant," she said slowly. "I didn't intend
to make people think things like that."
"Like what?" he asked gently.
"What you said—just now—that I might want a divorce."
"Do you?"
She did not reply; her face was turned now directly to the window
and he only saw the hand that rested on the pane tremble slightly.
He moved uneasily in his chair.
"I didn't know it was as bad as that, Eva!"
"As bad as that?" her voice trembled. "I don't understand."
"I didn't know that you wanted a divorce."
"It isn't that!"
He leaned forward, watching her, his expression singularly grave.
"Would you mind telling me just what you do mean?"
Eva turned from the window and came toward him, and as the light
fell on her face Astry was startled. He rose involuntarily from his seat
and Eva stood still, her slender hands clutching at the back of a
chair. She tried to speak twice before the words came.
"I can't bear it any longer, Johnstone; I'm going to tell the truth—the
whole truth."
He did not speak; he was watching her strangely.
She shivered and then went on, not looking at him, her voice at first
a mere whisper, growing a little firmer.
"Rachel married Belhaven—to save my good name."
He was still silent for a moment, regarding her.
"You mean that you—told me a falsehood that night?"
"About Rachel? Yes."
"Good God!"
She hid her face in her hands, but her voice, small and thin and
quivering, struggled on. She had to confess, she had to tell him, she
could endure it no longer.
"I lied about Rachel."
"And you—" he dragged out the words—"you were guilty?"
"Indeed—no! In thought, in the intention, yes." She broke off and
then after a moment of agony went on, her face still hidden in her
hands. "I was going to run away with him that day."
Astry did not speak, he did not even move, and Eva sank down into
a chair.
"I was going and you caught me; you accused me and—" she
stopped again and then went on, "and I was frightened. I'm a
coward; I told you a falsehood about Rachel, then I went to her—"
"And Rachel?" his voice was hoarse.
"She forgave me, she sacrificed herself for me; she's an angel."
"And you let her marry that—that scoundrel to save you?"
"I was afraid you'd kill him."
"He ought to have been killed."
Her head sank lower.
"It's incredible! To let your sister marry that scoundrel to save his
life, to shield you!"
"She's forgiven me," Eva's voice broke pitifully. "I told her—she—"
He had risen in his agitation and he swung around now, facing her.
"Did she know?"
"That I was guilty?" Eva turned darkly crimson. "No, not until the
other day—I told her—and she forgave me."
"It's past belief."
"That she should forgive me? Rachel? She's so good to me."
"I know Rachel, but it's past belief that you could let her do it,
sacrifice her to save that hound."
"Wait!" Eva rose; she tried to face him steadily. "Listen, you told me
that if she didn't marry him you'd kill him."
"Well?"
"That you'd kill him because of me. I told her that and she married
him to save my good name."
"It was my business to take care of your good name."
"No, it was mine," she was gaining strength now. "It was mine and
I'd failed. I was weak, wicked, foolish; I thought I loved him."
"You thought you loved him? Do you mean you didn't?"
"Not—not afterwards."
"Not after you saw the coward shield himself behind a woman?"
She wrung her hands together. "Yes, it was that; I hated that!"
Astry stood looking at her, a strange conflict of emotions in his face.
"Are you telling me the truth, Eva, or are you trying to shield him
again?"
"I'm telling you the truth. I thought I loved him, I was afraid of you,
—you frightened me sometimes then,—and I had loved him once, I
—"
"You never loved me then?"
She hesitated; again a dark blush mounted from throat to brow. "At
first I married you because—because Aunt Drusilla wanted it,
because—" she stopped.
"Yes—because?" he was watching her sternly.
"Because I wanted to make a great match."
"Oh, for my money!"
"If you want to put it that way."
"And afterwards you called back Belhaven?"
Again she assented.
"You thought it easy to be free of the millionaire after—" He
stopped, something in the mute agony of her attitude, her evident
humiliation, checking him.
"I thought I loved Belhaven," she said simply, determined not to
spare herself. "I was going to run away with him. He begged me to
—but it wasn't any more his fault than mine. I'm trying to tell you
the truth, the whole truth. Then came that night and your anger and
—and I saw he was afraid."
"The hound!"
"I saw he was afraid," her voice trailed on, quivering, "and I saw
how Rachel suffered. Johnstone, I've been punished; I deserve it,
but—the way is fearful, that way of the transgressors. Not my feet
only, but my heart bleeds. I went to Rachel; I begged her, I've
begged her twice, to get a divorce, to marry Charter; they love each
other. She won't do it—because—" Eva's voice broke with a sob
—"she says she can't, that it would ruin me."
"So it would—now."
"Then let it! I can't bear this, Johnstone; cast me out, help Rachel to
get free. I can't bear it any longer, it's killing me!"
"You've quite forgotten me, Eva."
"No, no, I haven't!" She burst into sudden, violent weeping. "I
haven't; I know now—I know you've suffered too. Johnstone, you
won't kill him?"
"Not now. It would disgrace Rachel. Think what I—your husband—
owe to Rachel."
"Then it's for her, you mean? It can't be done on her account?"
He nodded; speech was not easy.
Eva stood up, stretching out her arms with her impotent, childish
gesture of despair. "I never thought—oh, God, why can't I die?"
"Why didn't you tell me the truth then, as you're telling me now?
What if I killed him?"
"I was afraid; I'm a coward, I've told you so!" She stopped and
stood looking at him, then suddenly her face quivered. "Can you
forgive me? I've suffered, I'd like to feel that you'd forgiven me."
"Does it make any difference? Does it matter?"
"It matters to me."
He turned and met her eyes and his face paled. "Eva," he said
gently, "did you ever even for one moment love me?"
She pressed her hands together tightly, looking at him strangely.
"Would—would it make it easier to forgive me?"
"Yes," he replied slowly, "I, too, have traveled a long way, Eva; I,
too, came to find that there was no love for me; I, too, have
suffered,—I'm really quite human. But I could forgive you, I would
forgive you even this, if I felt that you'd ever been honest with me,
ever loved your husband for a moment in your life."
She drew a step nearer, her eyes dilated. "Did—did you ever love
me?"
"Once."
"And I lost it?"
"You didn't want it."
She covered her face with her hands again.
"And you—did you ever love me?" he asked bitterly.
"Not then."
"Do you mean?" he paused, and then unsteadily: "Have you come
back to your husband, Eva?"
"Not then—but now!"
Astry stood still; for a moment the fundamental forces of life seemed
suspended. He was amazed. Then he took a step forward, but
before he spoke Eva suddenly swayed and would have fallen but for
his arms around her.
He lifted her and carried her up-stairs. She was unconscious and her
head lay helpless, her pretty soft hair against his breast. He carried
her across the hall and into her own room and laid her on the bed
with a touch as tender as a woman's. The disdain and anger and
bitterness that had been waging a battle in his soul receded before
the wave of humanity, of pity, almost of tenderness, that suddenly
submerged his being. Her helplessness, the appeal of her childish
face, the evident grief and humiliation that she had suffered to tell
him the truth, touched his heart. He summoned her maid and then
went out softly and closed the door.
Before him he seemed to see the long, cruel way that her small,
bleeding feet had traveled, coming back at last to him.
In his heart he had already forgiven her.
XVIII
IT was nearly dusk on Thursday afternoon when Belhaven came in
and found Rachel in the living-room. He was pale and fagged and
came slowly across the room to the tea-table. She was sitting in a
deep chair by the fire but she rose mechanically and went to pour
tea for him. The little service had become so familiar that it was a
matter of habit. He glanced at her as he took the cup from her
hands and was startled by her face.
"There's something wrong, Rachel?"
"No, I'm a little tired, that's all."
His glance traveled around the room and came back to her again,
with a peculiar significance.
"I know that you're unhappy here," he said, a strong note of
restraint in his voice, unaware that he was repeating Astry's words
to Eva.
Rachel rallied her thoughts. "Not more so than you are," she replied
without bitterness.
"In a way that's true; you've been unhappy but, none the less,
you've made this house a home to me. I can pay no greater tribute
to your unselfishness; you've been cruelly placed but you've uttered
no reproaches."
"Oh, that isn't so much to my credit; reproaches are idle enough!"
He set his untasted tea on the table and leaned forward, looking at
her, his clasped hands between his knees, his dark face perturbed.
The light of the candelabrum on the tea-table flickered softly
between them; the long room was full of keen shadows. Rachel's
face, pale and spiritualized, was thrown into high relief; it had never
seemed so nearly beautiful, with the subtle charm of the shadowed
eyes and the soft, dark hair. She had passed through deep waters
but Charter knew she loved him; there was comfort in that. The
feeling of Charter's presence was with her, as it must be in great
love, even in the immortal moment of renunciation.
Belhaven, looking at her with a comprehension of suffering,
discerned the crisis. He saw that she had been deep in the struggle,
he divined that Eva had, at last, confessed the truth, and his soul
drew back shuddering from the thought of Rachel's judgment of him
—and the justice of it. There was a long silence. At last he broke it.
"Rachel, I've been thinking it all over and I've tried to put myself out
of it; for you it's intolerable."
She looked up in vague surprise; in the pause her mind had floated
with the stream and she had almost forgotten Belhaven's point of
view. "Not more intolerable than it has been—except I know now
that Eva deceived me. But I still believe you told me the truth, that
it's past with you both now, and I suppose it's best to let things go—
even for Astry."
"You never seem to think of yourself."
She colored deeply. "I've thought much of myself."
He saw the blush and a pang of hideous jealousy tore through the
remorse of his mood, but he gripped himself again. "I know you
hate me!" he began.
Rachel looked up quickly. "I don't hate you, far from it. I'm sorry for
you."
He smiled grimly, thinking of Charter. Had he come here to do
Charter's bidding after all? But he was resolved to go on. "Thank
you," he said, "I have, it seems, the beggar's meed—pity! Yet I feel
that my very presence here must be hateful to you. I've traded on
your generosity, your womanliness, even your pity. I've felt at times
that I'd be content to be a dog on your hearth-rug, but it's not so
now. Every day I'm with you I grow to love you more deeply—"
She turned to interrupt him but he held up a protesting hand. "Let
me finish. I know my love's hideous to you, but, none the less, I love
you for your sweetness, your justice, your kindness, and at last a
spark of generosity has been born in my own heart. I've been a
good deal of a scoundrel, Rachel; I can plead no decent excuse, but
there's enough manhood in me to feel that I've got to set you free."
A sudden hope, keen as joy, leaped in her heart for an instant, only
to pass into eclipse. "It's impossible without ruining Eva. I did it
myself, I dreaded the public scandal for her; it's just as much my
fault, in a way, as yours."
"There are ways that involve but little scandal."
Rachel sat looking at the fire. Her heart cried out again; she desired
happiness as fiercely as the most unreasoning child of circumstance,
but she remembered the obligations that had led to her sacrifice.
"It would be the end for Eva. Besides," she hesitated, "perhaps you
don't understand how I feel about marriage—I don't think I've got a
right to get a divorce. I knew what I was doing. You've blamed
yourself; have you ever thought of the wrong I did?"
"You?" He looked at her amazed, and encountering her eyes, that
had the sweet, abashed look of a frightened girl, a sudden wild hope
leaped up. "You mean you consider your marriage too sacred to
break?"
She inclined her head.
He drew a quick breath. "Rachel!" then the sight of her face, stricken
with grief and reluctance, brought him back to his senses. "I see,
you mean from the religious point of view. I've always understood
that; I knew you had scruples."
"I've always abhorred the light view, as if it wasn't sacred at all. I
know, I feel I wronged you when I married you. I haven't any right
to bring discredit on you by a divorce, unless—" she looked up
gravely—"if you wish to be free to—to find happiness elsewhere,
then I don't think I'd have the same right to—to insist on bearing my
share of it."
He met her eyes directly; his own face blanched. "You forget that I
love you!" he said slowly.
She colored painfully. "That's another thing that lies heavy on my
soul. I had no right to marry you—forgive me!"
"Rachel, could you ever—have loved me?"
She covered her face with her hands; she was thinking of Charter.
"N-no."
Belhaven still regarded her. He thought that she really abhorred him
and the idea stung him. He had traveled the long road, he had
reached the end of it, and met disaster and defeat. "You've refused
divorce," he said, in a strange voice, "yet you despise me. I suppose
I'm a very toad in your sight, but you would still save Eva! You're
right, I accept your wishes, but—there are other ways."
She did not understand him; she still hid her face, shutting out the
horror of the situation. Eva's lover as her husband! She could not
bring herself to speak to him.
"There are other ways," he repeated quietly, "but, for your sake, I
wish it wasn't so hard. I wish I could lighten it, Rachel."
"In a way you've done much to lighten it. I'm—I'm grateful."
He stood looking at her bowed head, remembering grimly that the
thought of his love had made her shudder as he had seen women
shudder at the sight of a reptile. Then he turned and went out
without another word.
It was a long time after that before Rachel seemed to be aware of
sounds and movements in the house. She had remained where
Belhaven left her, looking into the fire, her chin in her hand. Her gray
eyes, lit by the glow of the falling embers, were intent on some
distant thought, her gaze full of introspection; she saw nothing in
the room and, for a while, heard nothing. She seemed to have been
dragged through an endless chain of events, a series of agonizing
scenes. She was no longer what she had been a week ago, or even
yesterday; she seemed suddenly separated from herself, or was
rather a new self, born of suffering and joy,—the joy of feeling that
Charter knew,—and looking back at her old self,—the self of slow
growth, of childhood and girlhood and womanhood. She had,
indeed, been born again in anguish. She had renounced her own
happiness, and what had she gained? In that dreadful moment she
felt that she had not even gained her own salvation, for the awful
feeling of complicity in their guilt remained. She and Eva and
Belhaven had wretchedly cheated Astry; it was to Astry that she
owed the inexorable debt. If she could only feel that she had saved
Eva, brought her back to her husband!
Then came the temptation to escape from her sacrifice, to nullify her
act by accepting the first means of escape. Her heart clamored for
happiness and her love for Charter rebelled against all scruples.
What right had she to make Charter unhappy? There is no argument
so subtle, so unanswerable as the argument of love. Her own heart
cried out against her judgment; it would gladly have broken her
bonds and stultified her sacrifice. She thought that it would be easier
to bear if Charter knew, but it was a million times harder, for Charter
rebelled against it. Charter, who was good, saw no virtue in her self-
immolation; he, too, craved happiness. While Belhaven had offered
her divorce, at the cost, as she saw, of great personal misery, he
had offered her freedom. Her presence in the house had become
dear to him; her kindness, her quick sympathy, her womanliness,
had penetrated the armor of his worldliness and, at last, his soul had
risen to meet hers in an act of self-sacrifice. Though she did not
know it, she had gone far to save Belhaven. It would have been
natural for her to have despised him, to have let him feel himself
outside of her life, the cause of all, but she had not despised him,
she had been gentle and forbearing, and he had seen new and
charming qualities in her simplicity.
If Rachel could have known this, it would have comforted her a little,
but she had not even that small comfort as she sat brooding over
the fire. This was the Thursday of the dinner at the Astrys' and
Belhaven had reluctantly promised to go, for there were many
reasons that made him careful of the conventionalities; Rachel had
dined alone and early.
A big fire leaped in the old-fashioned chimney and there was a rich
and luxurious glow of color and light; the heavy, crimson curtains
were drawn over the windows, but it was storming outside, and she
heard the sleet on the window-panes. The wind shouted under the
old gables. Rachel went to a window and looked out; it was still light
enough to discern the cedars beaten by the gale. An old hemlock
near the house stretched spectral arms, sheeted in ice. The gray veil
of fog and rain cloaked the long slope of the landscape, and she
could not discover the distant city. It grew dark fast. She let the
curtain fall across the sash again and went to the fire, stretching out
both hands to the blaze with a shiver. A strange feeling of
uneasiness stirred in her heart, some vague forewarning; delicate
and floating like a tendril, it trembled back again into uncertainty.
She opened a book at random and began to read. It chanced to be a
life of St. Francis of Assisi, exquisitely illuminated, that Belhaven had
picked up for its artistic setting rather than its religious teachings, for
he was something of a connoisseur in books.
Rachel turned the leaf.
"Never set an empty pot to boil on the fire, in hope that your
neighbor will fill it!" ran the proverb.
She sighed. Had not Belhaven set his empty heart on the fire with
the hope that she would fill it for him? And she had not. In this,
then, Brother Giles understood the world; evidently he entertained
no hope for the filling of the pot.
Rachel turned the page, her fingers trembling slightly.
"And they twain ate the pottage of flour by reason of his
importunate charity. And they were refreshed much more by
devotion than by the food."
"And they twain ate of the pottage—" and she and Belhaven had
eaten of it to their despair. They had not been refreshed by
devotion, they had eaten it of necessity; had she found the key at
last? They had eaten the pottage and the taste of it was very bitter.
Rachel leaned forward and looked into the fire, where the red
embers fell and the flame continued to leap merrily.
"And they twain ate the pottage."
She heard the outer door open and close and a step come across
the hall. She turned sharply; some one had braved the storm. It was
Astry.
He stood in the door looking at her, as Belhaven had done. His fur
coat was thrown back and disclosed his evening dress; his face, as
usual, was pale and fair.
"I came for Belhaven," he said.
Rachel was surprised. "He's getting ready now; I thought the hour
was eight."
"It is, but I was determined to have no failures and I particularly
want Belhaven; you know he didn't want to come."
"Has any one failed you?"
"Only Mrs. Billop."
She smiled involuntarily. "Eva won't regret that."
"There are special dispensations. I don't see why we keep on inviting
those creatures unless it is because they're related to Paul. I
suppose Belhaven really means to come; it isn't informal enough to
let him off, you know."
"There seems to be no question about his coming."
Astry smiled again. "My dear Rachel," he said carelessly, "there
might be a question about it; if I were Belhaven there would be a
question about it."
She colored and Astry saw that she understood.
"Even an Arab has a right to protection; his bread and salt should
not be abused," he said, watching her.
"But his bread and salt protect the life of the stranger who tastes
them," she answered quickly.
Astry smiled bitterly. "I never thought of you as one to plead for the
transgressor."
Rachel put the little book down on the table and sat looking at him
with grave eyes, her heart throbbing heavily. Had Eva told him or—
some one else?
He came over and stood beside her. "Rachel, I'm deeply sorry that
there seems no way out, that you've got to bear it—or else your
sacrifice goes for nothing."
"You mean—" she could not go on.
"Eva has told me."
Rachel sank back in her chair, her hands trembling in her lap.
"Johnstone—you've forgiven her?"
He had averted his face and she saw only the outlines of the strong,
lithe figure and fine head. There was a brief significant pause, then
he turned, and Rachel saw the wreck of happiness in his face.
"I've tried to."
She hid her own face in her hands; the relief was intense that the
concealment was over! Astry turned and walked twice across the
room.
"Why didn't you let me kill him that night?"
"I couldn't—and I had to save Eva."
"That would have saved her and he—he needed killing!"
Rachel's hands fell in her lap again; she looked at him gravely, her
face tear-stained and pale. "Would it have saved the poor child to
have destroyed her name, to murder a man, and hang for it
yourself?"
He was silenced.
"That was it, that is what you would have done, Johnstone, and I
had to save you both. I did wrong, I've suffered for it, but oh, thank
God, Eva's told you the truth!"
"Rachel, I've felt, and I know Eva feels, that we've no right to accept
your sacrifice; we want to set you free even at the price of scandal.
Eva begs me to set you free, but—"
"You see how it is? If I get a divorce it will ruin Eva."
"I see how it is, otherwise I'd shoot that fellow now, but I can't
touch him without injury to you both. Yet—my God, Rachel, I've no
right to hold you to it."
"You don't. I feel so differently from you about it, you don't
understand. I can't break the marriage; I've got to take the
punishment, for I did it myself. I've got to keep my contract."
"You mean that your scruples won't permit you to break it?"
"Don't you understand? I was wrong to do it; I see it. I did it to save
Eva, but I had no right to take the vows as I did. I dare not break
them."
"Do you mean you're afraid of the scandal, or the odium of it all?"
"I'll have to be very plain—I'm afraid of God."
He stood looking at her a while in silence. Then his face changed
and softened.
"Like Felix, I'm almost persuaded," he said.
Rachel made a slight deprecating gesture. "Would I have made this
sacrifice if I'd contemplated making it void?"
He reflected. "I suppose not; you're a singular woman."
"I'm singularly placed."
He walked to and fro again. Rachel, meanwhile, heard Belhaven
slowly descending the stairs.
"Johnstone, you—you don't mean to quarrel with him now?"
"I've told you I can't; he's safe enough."
"I'm thankful for that!"
Astry stood still, regarding her earnestly, his heavy pale eyes
seeming to concentrate thought.
"You're unhappy."
She turned away. "Pardon me, we've said enough."
"I accept my rebuke as I long ago accepted my congé," he said
gently. "Nevertheless you're wretched, and you've been a good angel
to Eva; I owe about all I've got left to you."
Her lips quivered. "Please don't!"
He looked at her strangely. "I've been a brute, I've always been a
brute, and I've hurt you again. I feel as if we'd trapped you, Rachel;
can you forgive us?"
She looked beyond him, struggling to regain her composure, and she
heard the wind shouting under the gables while the rain leaped
against the window-panes. She could not answer Astry and before
he spoke again Belhaven came to the door.
"I heard you were waiting for me, Astry; it's certainly obliging to go
after your guests in such a storm. The rain's turning into snow and
sleet."
"My dear Belhaven," said Astry easily, "I particularly wanted you. I
have a word to say to you beforehand."
Belhaven glanced keenly from Astry to Rachel.
"I've no intentions of shirking my responsibilities," he said. "You'll
find me ready."
Astry turned. "Then we'd better be off. Good night, Rachel."
She made no reply but as she looked up she met Belhaven's eyes
and they were full of regret, of kindness, of appeal. The glance was
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebooknice.com

You might also like