The C++ Standard Library
The C++ Standard Library 英文版 带书签 高清晰The C++ Standard libraryC++ Standard library the: A Tutorial and ReferenceMany of the designations used by manufacturers and sellers to distinguish their products areclaimed as trademarks. Where those designations appear in this book and Addison WesleyLongman Inc. was aware of a trademark claim, the designations have been printed in initial capsor all caps.The authors and publisher have taken care in the preparation of this book, but make noexpressed or implied warranty of any kind and assume no responsibility for errors or omissionsNo liability is assumed for incidental or consequential damages in connection with or arising outof the use of the information or programs contained hereinThe publisher offers discounts on this book when ordered in quantity for special sales. For moreinformation, please contactAWL Direct salesAddison Wesley Longman, IncOne Jacob WayReading, Massachusetts 01867(781)944-3700VisitAwontheWeb:www.awl.com/cseng/Library of Congress Cataloging-in-Publication DataJosuttis. nicolai mThe C++ standard library: a tutorial and reference/Nicolai M. Josuttisp. cm.Includes bibliographical references and index1. C++(Computer program language)I. TitleQA76.73C153J691999005.133-dc2199-24977CIPCopyright C 1999 by Addison Wesley Longman, Inc.All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, ortransmitted, in any form, or by any means, electronic, mechanical, photocopying, recording, orotherwise, without the prior consent of the publisher. Printed in the United States of AmericaPublished simultaneously in Canada123456789CRW-0302010099First printing, July 1999dyne-bookThe C++ Standard libraryTable of contentsPrefaceAcknowledgmentsAbout this book1. 1 Why this Book1. 2 What You Should Know Before Reading this book1.3 Style and structure of the book1. 4 How to Read this book1. 5 State of the art1.6 Example Code and Additional information1.7 Feedback2. Introduction to C++ and the standard library2.1 History2.2 New Language Features2. 3 Complexity and the Big-O Notation3. General Concepts3.1 Namespace std3.2 Header files3.3 Error and EXception Handling3. 4 Allocators4, Utilities4. 1 Pairs4. 1. 1 Convenience Function make pairo4.1.2 EXamples of Pair Usage.2 Class auto ptr4.3 Numeric limits4.4 Auxiliary Functions4.5 Supplementary comparison Operators4.6 Header files and 5.The Standard Template Library5.1 STL Components5.2 Containers5.3 Iterators5.4 Algorithms5.5 Iterator Adapters5.6 Manipulating algorithms5.7 User-Defined generic functions5.8 Functions as Algorithm Arguments5.9 Function Obiects5.10 Container elements5.11 Errors and Exceptions Inside the STL5.12 Extending the stL6, STL Containers6. 1 Common Container abilities and operations6.2∨ ectors6.3Dequesdyne-bookThe C++ Standard library6. 4 Lists6. 5 Sets and multisets6.6 Maps and Multimaps6.7 Other stl containers6. 8 Implementing reference semantics6.9 When to use which container6. 10 Container Types and members in Deta了, stl Iterators7.1 Header files for iterators7.2 Iterator Categories7.3 Auxiliary Iterator Functions7.4 Iterator Adapters7.5 Iterator traits8. STL Function objects8.1 The Concept of Function obiects8.2 Predefined Function obiects8.3 Supplementary Composing Function Objects9. STL Algorithms9.1 Algorithm Header Files9.2 Algorithm Overview9.3 Auxiliary Functions9.4 The for each( Algorithm9.5 Nonmodifying algorithms9.6 Modifying algorithms9.7 Removing algorithms9. 8 Mutating Algorithms9.9 Sorting algorithms9.10 Sorted Range algorithms9.11 Numeric Algorithms10.Special Containers10.1 Stacks10.2 Queues10.3 Priority Queues10. 4 Bitsets11. Strings11. 1 Motivation11.2 Description of the String classes11.3 String Class in Detail12. Numerics12.1 Complex Numbers12.2 Valarray12.3 Global numeric functions13. Input/Output Using stream Classes13. Input/Output Using Stream Classes13.1 Common Background of I/o Streams13.2 Fundamental Stream Classes and obiectsdyne-bookThe C++ Standard library13.3 Standard Stream Operators < and>>13. 4 State of streams.3.5 Standard Input/Output Functions13.6 Manipulators13.7 Formatting13.8 Internationalization13.9 File Access13.10 Connecting Input and output streams13.11 Stream Classes for Strings13.12 Input/Output Operators for User-Defined Types3.13 The stream buffer Classes3.14 Performance issues14 Internationalization14.1 Different Character Encodings14.2 The Concept of Locales14.3 Locales in detail14 4 Facets in detail15. Allocators15.1 Using Allocators as an Application Programmer15.2 Using allocators as a library programmer15.3 The default allocator15. 4A User-Defined allocator15.5 Allocators in detail15.6 Utilities for Uninitialized Memory in DetailInternet resourcesWhere you can get the standardInternet Addresses/UrlsBibliographydyne-bookThe C++ Standard libraryPrefaceIn the beginning, I only planned to write a small German book(400 pages or so) about the C++standard library. That was in 1993. Now, in 1999 you see the result- an English book with morethan 800 pages of facts, figures, and examples. My goal is to describe the C++ standard libraryso that all (or almost all)your programming questions are answered before you think of thequestion. Note, however, that this is not a complete description of all aspects of the C++ standardlibrary. Instead, I present the most important topics necessary for learning and programming inC++ by using its standard libraryEach topic is described based on the general concepts this discussion then leads to the specificdetails needed to support every-day programming tasks. Specific code examples are provided tohelp you understand the concepts and the detailsThats it -in a nutshell i hope you get as much pleasure from reading this book as i did fromwriting it. Enjoy!dyne-bookThe C++ Standard libraryAcknowledgmentsThis book presents ideas, concepts, solutions, and examples from many sources. In a way itdoes not seem fair that my name is the only name on the cover. Thus Id like to thank all thepeople and companies who helped and supported me during the past few yearsFirst, I'd like to thank dietmar Kuhl. Dietmar is an expert on C+t, especially on input/outputstreams and internationalization(he implemented an l/0 stream library just for fun). He not onltranslated major parts of this book from German to English, he also wrote sections of this bookusing his expertise. In addition, he provided me with invaluable feedback over the yearsSecond, Id like to thank all the reviewers and everyone else who gave me their opinion. Thesepeople endow the book with a quality it would never have had without their input (Because thelist is extensive, please fogive me for any oversight. The reviewers for the English version of thisbook included Chuck Allison, Greg Comeau, James A. Crotinger, Gabriel Dos Reis, Alan ezustNathan Meyers, Werner Mossner, Todd Veldhuizen, Chichiang Wan, Judy Ward, and ThomasWikehult. the german reviewers included ralf boecker dirk herrmann dietmar Kuhl eddaLorke, Herbert Scheubner, Dominik Strasser, and Martin Weitzel. Additional input was providedby Matt Austern, Valentin Bonnard, Greg Colvin, Beman Dawes, Bill Gibbons, Lois Goldthwaite,Andrew Koenig, Steve Rumbsby, Bjarne Stroustrup, and david VandevoordeSpecial thanks to Dave Abrahams, Janet Cocker, Catherine Ohala, and Maureen Willard whoreviewed and edited the whole book very carefully. Their feedback was an incredible contributionto the quality of this bookA special thanks goes to my " personal living dictionary"-Herb Sutter -the author of thefamous"Guru of the Week"(a regular series of C++ programming problems that is published onthe comp. std. C++ moderated Internet newsgroup)Id also like to thank all the people and companies who gave me the opportunity to test myexamples on different platforms with different compilers. Many thanks to Steve Adamczyk, MikeAnderson, and John Spicer from EDG for their great compiler and their support. It was a big helpduring the standardization process and the writing of this book. Many thanks to P J Plauger andDinkumware, Ltd, for their early standard-conforming implementation of the C++ standard libraryMany thanks to andreas Hommel and metrowerks for an evaluative version of their Code WarriorProgramming Environment. Many thanks to all the developers of the free GNU and egcscompilers. Many thanks to Microsoft for an evaluative version of visual C++. Many thanks toRoland Hartinger from Siemens Nixdorf Informations Systems aG for a test version of their C++compiler. Many thanks to Topjects GmbH for an evaluative version of the Objectspace libraryimplementationMany thanks to everyone from Addison Wesley Longman who worked with me. Among othersthis includes Janet Cocker, Mike Hendrickson, Debbie Lafferty, Marina Lang, Chanda Leary,Catherine ohala, Marty rabinowitz, Susanne spitzer, and maureen willard It was funIn addition, Id like to thank the people at BREDEX Gmbh and all the people in the C++community, particularly those involved with the standardization process, for their support andpatience(sometimes I ask really silly questions)Last but not least, many thanks and kisses for my family: Ulli, Lucas, Anica, and Fredericdefinitely did not have enough time for them due to the writing of this bookHave fun and be human!dyne-bookThe C++ Standard libraryChapter 1. About this Book1. 1 Why this bookSoon after its introduction, C++ became a de facto standard in object-oriented programming Thised to the goal of standardization only by having a standard could programs be written thatwould run on different platforms- from Pcs to mainframes. Furthermore, a standard librarywould enable programmers to use general components and a higher level of abstraction withoutlosing portability, rather than having to develop all code from scratchThe standardization process was started in 1989 by an international ANSI/So committee. Itdeveloped the standard based on Bjarne Stroustrup's books The C++ Programming Languageand The Annotated C++ Reference Manual. After the standard was completed in 1997, severalformal motions by different countries made it an international iso and ansi standard in 1998The standardization process included the development of a C++ standard library. The libraryextends the core language to provide some general components. By using C++'s ability toprogram new abstract and generic types, the library provides a set of common classes andinterfaces. This gives programmers a higher level of abstraction. The library provides the ability touseString typesDifferent data structures such as dynamic arrays, linked lists, and binary treesDifferent algorithms(such as different sorting algorithmsNumeric classesInput/output (1/O)classesClasses for internationalization supportAll of these are supported by a fairly simple programming interface. These components are verimportant for many programs. These days, data processing often means inputting, computingprocessing, and outputting large amounts of data, which are often stringsThe library is not self-explanatory. To use these components and to benefit from their power, youneed a good introduction that explains the concepts and the important details instead of simplylisting the classes and their functions. This book is written exactly for that purpose. First, itintroduces the library and all of its components from a conceptional point of view. Next, itdescribes the details needed for practical programming. Examples are included to demonstratethe exact usage of the components. Thus, this book is a detailed introduction to the C++ libraryfor both the beginner and the practical programmer. Armed with the data provided herein, youshould be able to take full advantage of the C++ standard libraryCaveat:dont promise that everything described is easy and self-explanatory. The library provides a lotof flexibility, but flexibility for nontrivial purposes has a price. Beware that the library has traps andpitfalls, which I point out when we encounter them and suggest ways of avoiding them1.2 What You Should Know Before Reading this bookTo get the most from this book you should already know C++.(The book describes the standardcomponents of C++, but not the language itself. You should be familiar with the concepts ofclasses, inheritance, templates, and exception handling. However, you don't have to know all ofthe minor details about the language. The important details are described in the book( the minordyne-bookThe C++ Standard librarydetails about the language are more important for people who want to implement the libraryrather than use it). Note that the language has changed during the standardization process,soyour knowledge might not be up to date. Section 2. 2, provides a brief overview and introductionof the latest language features that are important for using the library. You should read thissection if you are not sure whether you know all the new features of C++(such as the keywordtypename and the concept of namespaces)1.3 Style and Structure of the BookThe C++ standard library provides different components that are somewhat but not totallyindependent of each other, so there is no easy way to describe each part without mentioningothers. I considered several different approaches for presenting the contents of this book. Onewas on the order of the C++ standard. However, this is not the best way to explain thecomponents of the C++ standard library from scratch. Another was to start with an overview of allcomponents followed by chapters that provided more details. Alternatively, I could have sortedthe components, trying to find an order that had a minimum of cross-references to other sectionsMy solution was to use a mixture of all three approaches. I start with a brief introduction of thegeneral concepts and the utilities that are used by the library. Then, I describe all thecomponents, each in one or more chapters. The first component is the standard template librarySTL). There is no doubt that the stl is the most powerful, most complex, and most exciting partof the library. Its design influences other components heavily. then i describe the more self-explanatory components, such as special containers, strings, and numeric classes. The nextcomponent discussed is one you probably know and use already: the IOStream library. It isfollowed by a discussion of internationalization, which had some influence on the lO StreamEach component description begins with the component's purpose, design, and some examplesNext, a detailed description follows that begins with different ways to use the component, as wellas any traps and pitfalls associated with it. The description usually ends with a reference sectionin which you can find the exact signature and definition of a component's classes and itsfunctionsThe following is a description of the book,s contents. The first four chapters introduce this bookand the C++ standard library in generaChapter 1: About this BookThis chapter (which you are reading right now) introduces the book's subject anddescribes its contentsChapter 2: Introduction to C++ and the standard libraryThis chapter provides a brief overview of the history of the C++ standard library and thecontext of its standardization. It also contains some general hints regarding the technicalbackground for this book and the library, such as new language features and the conceptof complexIChapter 3: General ConceptsThis chapter describes the fundamental concepts of the library that you needunderstand to work with all the components. In particular, it introduces the namespacstd, the format of header files, and the general support of error and exception handlingChapter 4: Utilitiesdyne-book
下载地址
用户评论