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 “” 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.
The C++ Programming
Language
Fourth Edition
Bjarne Stroustrup
Upper Saddle River, NJ • Boston • Indianapolis • San Francisco
New York • Totonto • Montreal • London • Munich • Paris • Madrid
Capetown • Sydney • Tokyo • Singapore • Mexico City
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.
The publisher offers excellent discounts on this book when ordered in quantity for
bulk purchases or special sales, which may include electronic versions and/or
custom covers and content particular to your business, training goals, marketing
focus, and branding interests. For more information, please contact:
U.S. Corporate and Government Sales
(800) 382-3419
corpsales@pearsontechgroup.com
For sales outside the United States, please contact:
International Sales
international@pearsoned.com
Visit us on the Web: informit.com/aw
Library of Congress Cataloging-in-Publication Data
Stroustrup, Bjarne.
The C++ programming language / Bjarne Stroustrup.—Fourth edition.
pages cm
Includes bibliographical references and index.
ISBN 978-0-321-56384-2 (pbk. : alk. paper)—ISBN 0-321-56384-0 (pbk. : alk.
paper)
1. C++ (Computer programming language) I. Title.
QA76.73.C153 S77 2013
005.13’3—
dc23 2013002159
Copyright © 2013 by Pearson Education, Inc.
All rights reserved. Printed in the United States of America. 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.
To obtain permission to use material from this work, please submit a written
request to Pearson Education, Inc., Permissions Department, One Lake Street,
Upper Saddle River, New Jersey 07458, or you may fax your request to (201) 236-
3290.
This book was typeset in Times and Helvetica by the author.
ISBN-13: 978-0-321-56384-2
ISBN-10: 0-321-56384-0
Text printed in the United States on recycled paper at Edwards Brothers Malloy in
Ann Arbor, Michigan.
Second printing, June 2013
Contents
Preface
Preface to the Fourth Edition
Preface to the Third Edition
Preface to the Second Edition
Preface to the First Edition
Part I: Introductory Material
1. Notes to the Reader
2. A Tour of C++: The Basics
3. A Tour of C++: Abstraction Mechanisms
4. A Tour of C++: Containers and Algorithms
5. A Tour of C++: Concurrency and Utilities
Part II: Basic Facilities
6. Types and Declarations
7. Pointers, Arrays, and References
8. Structures, Unions, and Enumerations
9. Statements
10. Expressions
11. Select Operations
12. Functions
13. Exception Handling
14. Namespaces
15. Source Files and Programs
Part III: Abstraction Mechanisms
16. Classes
17. Construction, Cleanup, Copy, and Move
18. Overloading
19. Special Operators
20. Derived Classes
21. Class Hierarchies
22. Run-Time Type Information
23. Templates
24. Generic Programming
25. Specialization
26. Instantiation
27. Templates and Hierarchies
28. Metaprogramming
29. A Matrix Design
Part IV: The Standard Library
30. Standard Library Summary
31. STL Containers
32. STL Algorithms
33. STL Iterators
34. Memory and Resources
35. Utilities
36. Strings
37. Regular Expressions
38. I/O Streams
39. Locales
40. Numerics
41. Concurrency
42. Threads and Tasks
43. The C Standard Library
44. Compatibility
Index