logo资料库

A Tour of C++/ C++语言导学.pdf

第1页 / 共193页
第2页 / 共193页
第3页 / 共193页
第4页 / 共193页
第5页 / 共193页
第6页 / 共193页
第7页 / 共193页
第8页 / 共193页
资料共193页,剩余部分请下载后查看
Contents
Preface
1 The Basics
1.1 Introduction
1.2 Programs
1.3 Hello, World!
1.4 Functions
1.5 Types, Variables, and Arithmetic
1.6 Scope
1.7 Constants
1.8 Pointers, Arrays, and References
1.9 Tests
1.10 Advice
2 User-Defined Types
2.1 Introduction
2.2 Structures
2.3 Classes
2.4 Unions
2.5 Enumerations
2.6 Advice
3 Modularity
3.1 Introduction
3.2 Separate Compilation
3.3 Namespaces
3.4 Error Handling
3.5 Advice
4 Classes
4.1 Introduction
4.2 Concrete Types
4.3 Abstract Types
4.4 Virtual Functions
4.5 Class Hierarchies
4.6 Copy and Move
4.7 Advice
5 Templates
5.1 Introduction
5.2 Parameterized Types
5.3 Function Templates
5.4 Concepts and Generic Programming
5.5 Function Objects
5.6 Variadic Templates
5.7 Aliases
5.8 Template Compilation Model
5.9 Advice
6 Library Overview
6.1 Introduction
6.2 Standard-Library Components
6.3 Standard-Library Headers and Namespace
6.4 Advice
7 Strings and Regular Expressions
7.1 Introduction
7.2 Strings
7.3 Regular Expressions
7.4 Advice
8 I/O Streams
8.1 Introduction
8.2 Output
8.3 Input
8.4 I/O State
8.5 I/O of User-Defined Types
8.6 Formatting
8.7 File Streams
8.8 String Streams
8.9 Advice
9 Containers
9.1 Introduction
9.2 vector
9.3 list
9.4 map
9.5 unordered_map
9.6 Container Overview
9.7 Advice
10 Algorithms
10.1 Introduction
10.2 Use of Iterators
10.3 Iterator Types
10.4 Stream Iterators
10.5 Predicates
10.6 Algorithm Overview
10.7 Container Algorithms
10.8 Advice
11 Utilities
11.1 Introduction
11.2 Resource Management
11.3 Specialized Containers
11.4 Time
11.5 Function Adaptors
11.6 Type Functions
11.7 Advice
12 Numerics
12.1 Introduction
12.2 Mathematical Functions
12.3 Numerical Algorithms
12.4 Complex Numbers
12.5 Random Numbers
12.6 Vector Arithmetic
12.7 Numeric Limits
12.8 Advice
13 Concurrency
13.1 Introduction
13.2 Tasks and threads
13.3 Passing Arguments
13.4 Returning Results
13.5 Sharing Data
13.6 Waiting for Events
13.7 Communicating Tasks
13.8 Advice
14 History and Compatibility
14.1 History
14.2 C++11 Extensions
14.3 C/C++ Compatibility
14.4 Bibliography
14.5 Advice
Index
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
R
S
T
U
V
W
X
ptg11539604
A Tour of C++
The C++ In-Depth Series BJARNE STROUSTRUP, Editor ‘‘I have made this letter longer than usual, because I lack the time to make it short.’’ — Blaise Pascal The C++ In-Depth Series is a collection of concise and focused books providing real-world pro- grammers with reliable information about the C++ programming language. Selected by the designer and original implementer of C++, Bjarne Stroustrup, and written by experts in the field, each book in this series presents either a single topic, at a technical level appropriate to that topic, or a fast-paced overview, for a quick understanding of broader language features. Its practical approach, in either case, is designed to lift professionals (and aspiring professionals) to the next level of programming skill or knowledge. These short books are meant to be read and referenced without the distraction of unrelated material. As C++ matures, it becomes increasingly important to be able to separate essential infor- mation from hype and glitz, and to find the deep content and practical guidance needed for contin- ued development. The C++ In-Depth Series provides the background, tools, concepts, techniques, and new approaches that can enable this development, and thereby give readers a valuable, critical edge. ptg11539604
A Tour of C++ Bjarne Stroustrup Upper Saddle River, NJ • Boston • Indianapolis • San Francisco New York • Toronto • Montreal • London • Munich • Paris • Madrid Capetown • Sydney • Tokyo • Singapore • Mexico City ptg11539604
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. A Tour of C++ / Bjarne Stroustrup. pages cm Includes bibliographical references and index. ISBN 978-0-321-958310 (pbk. : alk. paper)—ISBN 0-321-958314 (pbk. : alk. paper) 1. C++ (Computer programming language) I. Title. QA76.73.C153 S77 2013 005.13’3—dc23 Copyright © 2014 by Pearson Education, Inc. 2013002159 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-958310 ISBN-10: 0-321-958314 Te xt printed in the United States on recycled paper at Edwards Brothers Malloy in Ann Arbor, Michigan. First printing, September 2013 ptg11539604
Contents Contents Preface 1 The Basics 1.1 Introduction ................................................................................. 1 1.2 Programs ..................................................................................... 1 1.3 Hello, World! .............................................................................. 2 1.4 Functions ..................................................................................... 3 1.5 Types, Variables, and Arithmetic ................................................ 5 1.6 Scope ........................................................................................... 8 1.7 Constants ..................................................................................... 8 1.8 Pointers, Arrays, and References ................................................ 9 1.9 Tests ............................................................................................ 12 1.10 Advice ......................................................................................... 14 2 User-Defined Types 2.1 Introduction ................................................................................. 15 2.2 Structures .................................................................................... 16 2.3 Classes ........................................................................................ 17 2.4 Unions ......................................................................................... 19 2.5 Enumerations .............................................................................. 20 2.6 Advice ......................................................................................... 21 v ix 1 15 ptg11539604
vi Contents 3 Modularity 3.1 Introduction ................................................................................. 23 3.2 Separate Compilation .................................................................. 24 3.3 Namespaces ................................................................................. 26 3.4 Error Handling ............................................................................ 27 3.5 Advice ......................................................................................... 31 4 Classes 4.1 Introduction ................................................................................. 33 4.2 Concrete Types ............................................................................ 34 4.3 Abstract Types ............................................................................ 39 4.4 Virtual Functions ......................................................................... 42 4.5 Class Hierarchies ........................................................................ 42 4.6 Copy and Move ........................................................................... 48 4.7 Advice ......................................................................................... 56 5 Templates 5.1 Introduction ................................................................................. 59 5.2 Parameterized Types ................................................................... 59 5.3 Function Templates ..................................................................... 62 5.4 Concepts and Generic Programming .......................................... 62 5.5 Function Objects ......................................................................... 64 5.6 Variadic Templates ...................................................................... 66 5.7 Aliases ......................................................................................... 67 5.8 Template Compilation Model ..................................................... 68 5.9 Advice ......................................................................................... 68 6 Library Overview 6.1 Introduction ................................................................................. 71 6.2 Standard-Library Components .................................................... 72 6.3 Standard-Library Headers and Namespace ................................. 72 6.4 Advice ......................................................................................... 74 7 Strings and Regular Expressions 7.1 Introduction ................................................................................. 75 7.2 Strings ......................................................................................... 75 7.3 Regular Expressions .................................................................... 78 7.4 Advice ......................................................................................... 84 23 33 59 71 75 ptg11539604
8 I/O Streams 8.1 Introduction ................................................................................. 85 8.2 Output ......................................................................................... 86 Input ............................................................................................ 87 8.3 8.4 I/O State ...................................................................................... 89 8.5 I/O of User-Defined Types .......................................................... 90 8.6 Formatting ................................................................................... 91 8.7 File Streams ................................................................................ 92 8.8 String Streams ............................................................................. 92 8.9 Advice ......................................................................................... 93 9 Containers Introduction ................................................................................. 95 9.1 vector ........................................................................................... 96 9.2 list ................................................................................................ 100 9.3 9.4 map .............................................................................................. 101 9.5 unordered_map ............................................................................ 102 9.6 Container Overview .................................................................... 103 9.7 Advice ......................................................................................... 104 10 Algorithms 10.1 Introduction ................................................................................. 107 10.2 Use of Iterators ............................................................................ 108 10.3 Iterator Types .............................................................................. 111 10.4 Stream Iterators ........................................................................... 112 10.5 Predicates .................................................................................... 113 10.6 Algorithm Overview ................................................................... 114 10.7 Container Algorithms ................................................................. 115 10.8 Advice ......................................................................................... 115 11 Utilities 11.1 Introduction ................................................................................. 117 11.2 Resource Management ................................................................ 117 11.3 Specialized Containers ................................................................ 121 11.4 Time ............................................................................................ 125 11.5 Function Adaptors ....................................................................... 125 11.6 Type Functions ............................................................................ 128 11.7 Advice ......................................................................................... 131 vii 85 95 107 117 ptg11539604
分享到:
收藏