The C++ Standard Library: A Tutorial and Reference / Edition 1

Hardcover (Print)
Used and New from Other Sellers
Used and New from Other Sellers
from $2.14
Usually ships in 1-2 business days
(Save 97%)
Other sellers (Hardcover)
  • All (14) from $2.14   
  • New (2) from $70.00   
  • Used (12) from $2.14   
Close
Sort by
Page 1 of 1
Showing All
Note: Marketplace items are not eligible for any BN.com coupons and promotions
$70.00
Seller since 2014

Feedback rating:

(113)

Condition:

New — never opened or used in original packaging.

Like New — packaging may have been opened. A "Like New" item is suitable to give as a gift.

Very Good — may have minor signs of wear on packaging but item works perfectly and has no damage.

Good — item is in good condition but packaging may have signs of shelf wear/aging or torn packaging. All specific defects should be noted in the Comments section associated with each item.

Acceptable — item is in working order but may show signs of wear such as scratches or torn packaging. All specific defects should be noted in the Comments section associated with each item.

Used — An item that has been opened and may show signs of wear. All specific defects should be noted in the Comments section associated with each item.

Refurbished — A used item that has been renewed or updated and verified to be in proper working condition. Not necessarily completed by the original manufacturer.

New
Brand new.

Ships from: acton, MA

Usually ships in 1-2 business days

  • Standard, 48 States
  • Standard (AK, HI)
$99.97
Seller since 2007

Feedback rating:

(127)

Condition: New
Hardcover New 0201379260 Brand new book. STUDENT US EDITION. Never used. Nice gift. Best buy. Shipped promptly and packaged carefully.

Ships from: Woodinville, WA

Usually ships in 1-2 business days

  • Canadian
  • International
  • Standard, 48 States
  • Standard (AK, HI)
  • Express, 48 States
  • Express (AK, HI)
Page 1 of 1
Showing All
Close
Sort by

Overview

The C standard library provides a set of common classes and interfaces that greatly extend the core C language. The library, however, is not self-explanatory. To make full use of its components-and to benefit from their power-you need a resource that does far more than list the classes and their functions.

The C Standard Library not only provides comprehensive documentation of each library component, it also offers clearly written explanations of complex concepts, describes the practical programming details needed for effective use, and gives example after example of working code.

This thoroughly up-to-date book reflects the newest elements of the C standard library incorporated into the full ANSI/ISO C language standard. In particular, the text focuses on the Standard Template Library (STL), examining containers, iterators, function objects, and STL algorithms. You will also find detailed coverage of special containers, strings, numerical classes, internationalization, and the IOStream library. Each component is presented in depth, with an introduction to its purpose and design, examples, a detailed description, traps and pitfalls, and the exact signature and definition of its classes and their functions. An insightful introduction to fundamental concepts and an overview of the library will help bring newcomers quickly up to speed.

Comprehensive, detailed, readable, and practical, The C Standard Library is the C resource you will turn to again and again. An accompanying Web site, including source code, can be found at ...

Read More Show Less

Editorial Reviews

From Barnes & Noble
The Barnes & Noble Review
The C++ Standard Library enables programmers to use general components and a higher level of abstraction, enhancing efficiency and reliability without compromising portability. The library is not self-explanatory or fully consistent, and there are still some traps for the unwary. But the advantages far outweigh the problems, especially if you've got an expert book like Nicolai Josuttis' C++ Standard Library to help you.

Josuttis starts with an overview of the standard library, and its key interrelationships with the core language. He presents detailed coverage of the STL, the most powerful, complex, and exciting part of the library; then covers special containers, strings, numeric classes, and internationalization; and helps you get more out of a component you're probably already using: the IOStream library. Every component description includes purpose, design, code examples, practical scenarios, pitfalls, and in most cases, reference sources. Whether you need a tutorial or reference, this book delivers the goods.— (Bill Camarda, bn.com, editor)

Jack Woehr

To comprehend the meaning and usage of the standard library classes mandated in the ANS/ISO C++ Standard of 1997, there are two ways to go:

  • You can start from familiarity with the theory of collections, streams, and algorithms and then read the source code of an extant library implementation.
  • Or you can read a book like Nicolai Josuttis's The C++ Standard Library.
The C++ Standard Library is the best overview of its topic in the popular technical press that I've seen so far. A few years ago I was looking for this book, but it hadn't been written yet, so I opted for course 1 above. It's really more orderly to read the book.

The C++ Standard Library is essentially a perfect book. It's so good that it can't be great. The author knows his field so well that there's no sense of striving in his explanations. (Josuttis is a member of the C++ Standard Committee library working group.)

The C++ Standard Library is organized in the Gnu Texinfo manual style, which evolved on the MIT-Stanford Free Software axis in the 1980s. No surprises, we know how to read this one without the author lecturing us on conventions employed in the text.

What's covered? The whole C++ standard libraries. Well-phrased, accurate, authoritative, and scientific, Josuttis has authored the quintessential user's guide on this subject. Let others focus on patterns of usage -- the community of intermediate C++ programmers pursuing standard class expertise now has its classic.
Electronic Review of Computer Books

Booknews
Introduces the C++ standard library and all its components from a conceptual point of view, then describes the details for programming with the standard template library (STL), special containers, strings, numeric classes, and the IOStream library. Each component description features its purpose and design, examples and suggested uses, traps and pitfalls, and the exact signature and definition of its classes and their functions. The book concludes with discussions of internationalization and allocators. Annotation c. Book News, Inc., Portland, OR (booknews.com)
Read More Show Less

Product Details

  • ISBN-13: 9780201379266
  • Publisher: Addison-Wesley
  • Publication date: 8/6/1999
  • Edition description: New Edition
  • Edition number: 1
  • Pages: 912
  • Product dimensions: 7.56 (w) x 9.48 (h) x 1.83 (d)

Meet the Author


Nicolai M. Josuttis is an independent technical consultant who designs object-oriented software for the telecommunication, traffic, finance, and manufacturing industries. He is an active member of the C++ Standard Committee library working group and a partner at System Bauhaus, a German group of recognized object-oriented system development experts. Josuttis has written several books on object-oriented programming and C++, including Die C++-Standardbibliothek and Objektorientiertes Programmieren in C++.
Read More Show Less

Read an Excerpt

In 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 more than 800 pages of facts, figures, and examples. My goal is to describe the C++ Standard Library so that all (or almost all) your programming questions are answered before you think of the question. Note, however, that this is not a complete description of all aspects of the C++ Standard Library. Instead, I present the most important topics necessary for learning and programming in C++by using its standard library.

Each topic is described based on the general concepts;this discussion then leads to the specific details needed to support everyday programming tasks. Specific code examples are provided to help you understand the concepts and the details.

That's it--in a nutshell. I hope you get as much pleasure from reading this book as I did from writing it. Enjoy!

Acknowledgments

This book presents ideas, concepts,solutions, and examples from many sources. In a way it does not seem fair that my name is the only name on the cover. Thus, I'd like to thank all the people and companies who helped and supported me during the past few years.

First, I'd like to thank Dietmar Kuhl. Dietmar is an expert on C++, especially on input/output streams and internationalization (he implemented an I/O stream library just for fun). He not only translated major parts of this book from German to English, he also wrote sections of this book using his expertise. In addition, he provided me with invaluable feedback over the years.

Second, I'd like to thank all the reviewers and everyone else who gave me their opinion. These people endow the book with a quality it would never have had without their input. (Because the list is extensive, please forgive me for any oversight.) The reviewers for the English version of this book included Chuck Allison, Greg Comeau, James A. Crotinger, Gabriel Dos Reis, Alan Ezust, Nathan Meyers, Werner Mossner, Todd Veldhuizen, Chichiang Wan, Judy Ward, and Thomas Wikehult. The German reviewers included Ralf Boecker, Dirk Herrmann, Dietmar Kuhl, Edda Lorke, Herbert Scheubner, Dominik Strasser, and Martin Weitzel. Additional input was provided by Matt Austern, Valentin Bonnard, Greg Colvin, Beman Dawes, Bill Gibbons, Lois Goldthwaite, Andrew Koenig, Steve Rumbsby, Bjarne Stroustrup, and David Vandevoorde.

Special thanks to Dave Abrahams, Janet Cocker, Catherine Ohala, and Maureen Willard who reviewed and edited the whole book very carefully. Their feedback was an incredible contribution to the quality of this book.

A special thanks goes to my "personal living dictionary"--Herb Sutter--the author of the famous "Guru of the Week" (a regular series of C++ programming problems that is published on the comp.std.c++.moderated Internet newsgroup).

I'd also like to thank all the people and companies who gave me the opportunity to test my examples on different platforms with different compilers. Many thanks to Steve Adamczyk, Mike Anderson, and John Spicer from EDG for their great compiler and their support. It was a big help during the standardization process and the writing of this book. Many thanks to P. J. Plauger and Dinkumware, Ltd, for their early standard-conforming implementation of the C++ Standard Library. Many thanks to Andreas Hommel and Metrowerks for an evaluative version of their CodeWarrior Programming Environment. Many thanks to all the developers of the free GNU and egcs compilers. Many thanks to Microsoft for an evaluative version of Visual C++. Many thanks to Roland 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 library implementation.

And, of course many thanks for those who invented, designed, or implemented C++ or parts of the library. Among others are Bjarne Stroustrup, Alexander Stepanov, Meng Lee, Matt Austern, Boris P. Fomichev, and all the other guys who wrote the SGI STL and the STLport.

Many thanks to everyone from Addison Wesley Longman who worked with me. Among others this includes Janet Cocker, Mike Hendrickson, Debbie Lafferty, Marina Lang, Chanda Leary, Catherine Ohala, Marty Rabinowitz, Susanne Spitzer, and Maureen Willard. It was fun.

In addition, I'd 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 and patience (sometimes I ask really silly questions).

Last but not least, many thanks and kisses for my family: Ulli, Lucas, Anica, and Frederic. I definitely did not have enough time for them due to the writing of this book.

Have fun and be human!

About this Book

Soon after its introduction, C++ became a de facto standard in object-oriented programming. This led to the goal of standardization. Only by having a standard, could programs be written that would run on different platforms--from PCs to mainframes. Furthermore, a standard C++ library would enable programmers to use general components and a higher level of abstraction without losing portability, rather than having to develop all code from scratch.

The standardization process was started in 1989 by an international ANSI/ISO committee. It developed the standard based on Bjarne Stroustrup's books (The C++ Programming Language) and (The Annotated C++ Reference Manual). After the standard was completed in 1997,several formal motions by different countries made it an international ISO and ANSI standard in 1998. The standardization process included the development of a C++ Standard Library. The library extends the core language to provide some general components. By using C++'s ability to program new abstract and generic types, the library provides a set of common classes and interfaces. This gives programmers a higher level of abstraction. The library provides the ability to use string types, different data structures (such as dynamic arrays, linked lists, and binary trees), different algorithms (such as different sorting algorithms), numeric classes, input/output (I/O) classes, and classes for internationalization support.

All of these are supported by a fairly simple programming interface. These components are very important for many programs. These days, data processing often means inputting, computing, processing, and outputting large amounts of data, which are often strings.

The library is not self-explanatory. To use these components and to benefit from their power,you need a good introduction that explains the concepts and the important details instead of simply listing the classes and their functions. This book is written exactly for that purpose. First, it introduces the library and all of its components from a conceptional point of view. Next, it describes the details needed for practical programming. Examples are included to demonstrate the exact usage of the components. Thus, this book is a detailed introduction to the C++ library for both the beginner and the practical programmer. Armed with the data provided herein, you should be able to take full advantage of the C++ Standard Library.

Caveat

I don't promise that everything described is easy and self-explanatory. The library provides a lot of flexibility,but flexibility for nontrivial purposes has a price. Beware that the library has traps and pitfalls,which I point out when we encounter them and suggest ways of avoiding them.

What You Should Know Before Reading this Book

To get the most from this book you should already know C++. (The book describes the standard components of C++, but not the language itself.) You should be familiar with the concepts of classes, inheritance, templates, and exception handling. However, you don't have to know all of the minor details about the language. The important details are described in the book (the minor details about the language are more important for people who want to implement the library rather than use it). Note that the language has changed during the standardization process,so your knowledge might not be up to date.

The section on newlang features provides a brief overview and introduction of the latest language features that are important for using the library. You should read this section if you are not sure whether you know all the new features of C++ (such as the keyword {\tt typename} and the concept of namespaces).

Style and Structure of the Book

The C++ Standard Library provides different components that are somewhat but not totally independent of each other,so there is no easy way to describe each part without mentioning others. I considered several different approaches for presenting the contents of this book. One was on the order of the C++ standard. However, this is not the best way to explain the components of the C++ Standard Library from scratch. Another was to start with an overview of all components followed by chapters that provided more details. Alternatively, I could have sorted the components, trying to find an order that had a minimum of cross-references to other sections. My solution was to use a mixture of all three approaches.

I start with a brief introduction of the general concepts and the utilities that are used by the library. Then, I describe all the components, each in one or more chapters. The first component is the standard template library (STL). There is no doubt that the STL is the most powerful, most complex, and most exciting part of 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 next component discussed is one you probably know and use already: the iostreamlib{}. It is followed by a discussion of internationalization, which had some influence on the iostreamlib{}.

Each component description begins with the component's purpose, design, and some examples. Next, a detailed description follows that begins with different ways to use the component, as well as any traps and pitfalls associated with it. The description usually ends with a reference section, in which you can find the exact signature and definition of a component's classes and its functions.

How to Read this Book

This book is a mix of introductory user's guide and structured reference manual regarding the C++ Standard Library. The individual components of the C++ Standard Library are independent of each other, to some extent, so after reading Chapters 2 through 4 you could read the chapters that discuss the individual components in any order. Bear in mind,that Chapters 5 through 9 all describe the same component. To understand the other STL chapters, you should start with the introduction to the STL in chapter 5.

If you are a C++ programmer who wants to know, in general, the concepts and all parts of the library, you could simply read the book from the beginning to the end. However, you should skip the reference sections (which usually are named something like "...{} in detail}"). To program with certain components of the C++ Standard Library, the best way to find something is to use the index. I have tried to make the index very comprehensive to save you time when you are looking for something.

I can't explain all aspects at the same time, so you will find many cross references. It is always a problem to decide whether to follow them. If the cross reference refers to a section that will follow soon, take it as hint that I return to an aspect later. You should follow the cross reference only if you are searching for certain aspects or details and the cross reference seems to lead to details concerning your problem or its solution.

In my experience, the best way to learn something new is to look at examples. Therefore, you'll find a lot of examples throughout the book. They may be a few lines of code or complete programs. In the latter case, you'll find the name of the file containing the program's first comment line. You can find the files on the Internet at my Web site.

State of the Art

While I was writing this book,the C++ standard was completed. Please bear in mind that some compilers might not yet confirm to it. This will most likely change in the near future. As a consequence, you might discover that not all things covered in this book work as described on your system,and you may have to change example programs to fit your specific environment. I can compile almost all example programs with version 2.8 or higher of the EGCS compiler, which is free for almost all platforms and available on the Internet and on several software CDs.

Example Code and Additional Information

You can access all example programs and acquire more informations about this book and the C++ Standard Library from my Web site. Please read the {\tt README} file for further details. Also, you can find a lot of additional information about this topic on the Internet. See Internet Resources on page 743 for details.

Feedback

I welcome your feedback (good and bad) on this book. I tried to prepare it carefully; however, I'm human, and at some time I have to stop writing and tweaking. So, you may find some errors, inconsistencies, or subjects that could be described better. Your feedback will give me the chance to improve later editions. The best way to reach me is by Email: libbook@josuttis.

You can also reach me by phone, fax, or "snail" mail:
Nicolai M. Josuttis
Berggarten 9
D--38108
Braunschweig
Germany
Phone: +49 5309 5747
Fax: +49 5309 5774

Many thanks.
Read More Show Less

Table of Contents

Preface
Acknowledgments
1 About this Book
1.1 Why this Book
1.2 What You Should Know Before Reading this Book
1.3 Style and Structure of the Book
1.4 How to Read this Book
1.5 State of the Art
1.6 Example Code and Additional Information
1.7 Feedback

2 Introduction to C++ and the Standard Library
2.1 History
2.2 New Language Features
2.2.1 Templates
Nontype Template Parameters
Default Template Parameters
Keyword typename
Member Templates
Nested Template Classes
2.2.2 Explicit Initialization for Fundamental Types
2.2.3 Exception Handling
2.2.4 Namespaces
2.2.5 Type bool
2.2.6 Keyword explicit
2.2.7 New Operators for Type Conversion
2.2.8 Initialization of Constant Static Members
2.2.9 Definition of main()
2.3 Complexity and the Big-O Notation

3 General Concepts
3.1 Namespace std
3.2 Header Files
3.3 Error and Exception Handling
3.3.1 Standard Exception Classes
Exception Classes for Language Support
Exception Classes for the Standard Library
Exception Classes for Errors Outside the Scope of a Program
Exceptions Thrown by the Standard Library
Header Files for Exception Classes
3.3.2 Members of Exception Classes
3.3.3 Throwing Standard Exceptions
3.3.4 Deriving Standard Exception Classes
3.4 Allocators

4 Utilities
4.1 Pairs
Pair Comparisons
4.1.1 Convenience Function make_pair()
4.1.2 Examples of Pair Usage
4.2 Class auto_ptr
4.2.1 Motivation of Class auto_ptr
4.2.2 Transfer of Ownership by auto_ptr
Source and Sink
Caveat
4.2.3 auto_ptrs as Members
4.2.4 Misusing auto_ptrs
4.2.5 auto_ptr Examples
4.2.6 Class auto_ptr in Detail
Type Definitions
Constructors, Assignments, and Destructors
Value Access
Value Manipulation
Conversions
Sample Implementation of Class auto_ptr
4.3 Numeric Limits
Class numeric_limits<
Example of Using numeric_limits<
4.4 Auxiliary Functions
4.4.1 Processing the Minimum and Maximum
4.4.2 Swapping Two Values
4.5 Supplementary Comparison Operators
4.6 Header Files 4.6.1 Definitions in 4.6.2 Definitions in
5 The Standard Template Library
5.1 STL Components
5.2 Containers
5.2.1 Sequence Containers
Vectors
Deques
Lists
Strings
Ordinary Arrays
5.2.2 Associative Containers
5.2.3 Container Adapters
5.3 Iterators
5.3.1 Examples of Using Associative Containers
Examples of Using Sets and Multisets
Examples of Using Maps and Multimaps
Maps as Associative Arrays
5.3.2 Iterator Categories
5.4 Algorithms
5.4.1 Ranges
5.4.2 Handling Multiple Ranges
5.5 Iterator Adapters
5.5.1 Insert Iterators
5.5.2 Stream Iterators
5.5.3 Reverse Iterators
5.6 Manipulating Algorithms
5.6.1 "Removing" Elements
5.6.2 Manipulating Algorithms and Associative Containers
5.6.3 Algorithms versus Member Functions
5.7 User-Defined Generic Functions
5.8 Functions as Algorithm Arguments
5.8.1 Examples of Using Functions as Algorithm Arguments
5.8.2 Predicates
Unary Predicates
Binary Predicates
5.9 Function Objects
5.9.1 What Are Function Objects?
5.9.2 Predefined Function Objects
5.10 Container Elements
5.10.1 Requirements for Container Elements
5.10.2 Value Semantics or Reference Semantics
5.11 Errors and Exceptions Inside the STL
5.11.1 Error Handling
5.11.2 Exception Handling
5.12 Extending the STL

6 STL Containers
6.1 Common Container Abilities and Operations
6.1.1 Common Container Abilities
6.1.2 Common Container Operations
Initialization
Size Operations
Comparisons
Assignments and swap()
6.2 Vectors
6.2.1 Abilities of Vectors
Size and Capacity
6.2.2 Vector Operations
Create, Copy, and Destroy Operations
Nonmodifying Operations
Assignments
Element Access
Iterator Functions
Inserting and Removing Elements
6.2.3 Using Vectors as Ordinary Arrays
6.2.4 Exception Handling
6.2.5 Examples of Using Vectors
6.2.6 Class vector
6.3 Deques
6.3.1 Abilities of Deques
6.3.2 Deque Operations
6.3.3 Exception Handling
6.3.4 Examples of Using Deques
6.4 Lists
6.4.1 Abilities of Lists
6.4.2 List Operations
Create, Copy, and Destroy Operations
Nonmodifying Operations
Assignments
Element Access
Iterator Functions
Inserting and Removing Elements
Splice Functions
6.4.3 Exception Handling
6.4.4 Examples of Using Lists
6.5 Sets and Multisets
6.5.1 Abilities of Sets and Multisets
6.5.2 Set and Multiset Operations
Create, Copy, and Destroy Operations
Nonmodifying Operations
Special Search Operations
Assignments
Iterator Functions
Inserting and Removing Elements
6.5.3 Exception Handling
6.5.4 Examples of Using Sets and Multisets
6.5.5 Example of Specifying the Sorting Criterion at Runtime
6.6 Maps and Multimaps
6.6.1 Abilities of Maps and Multimaps
6.6.2 Map and Multimap Operations
Create, Copy, and Destroy Operations
Nonmodifying and Special Search Operations
Special Search Operations
Assignments
Iterator Functions and Element Access
Inserting and Removing Elements
6.6.3 Using Maps as Associative Arrays
6.6.4 Exception Handling
6.6.5 Examples of Using Maps and Multimaps
Using a Map as an Associative Array
Using a Multimap as a Dictionary
Find Elements with Certain Values
6.6.6 Example with Maps, Strings, and Sorting Criterion at Runtime
6.7 Other STL Containers
6.7.1 Strings as STL Containers
6.7.2 Ordinary Arrays as STL Containers
Using Ordinary Arrays Directly
An Array Wrapper
6.7.3 Hash Tables
6.8 Implementing Reference Semantics
6.9 When to Use which Container
6.10 Container Types and Members in Detail
6.10.1 Type Definitions
6.10.2 Create, Copy, and Destroy Operations
6.10.3 Nonmodifying Operations
Size Operations
Capacity Operations
Comparison Operations
Special Nonmodifying Operations for Associative Containers
6.10.4 Assignments
6.10.5 Direct Element Access
6.10.6 Operations to Generate Iterators
6.10.7 Inserting and Removing Elements
6.10.8 Special Member Functions for Lists
6.10.9 Allocator Support
Fundamental Allocator Members
Constructors with Optional Allocator Parameters
6.10.10 Overview of Exception Handling in STL Containers

7 STL Iterators
7.1 Header Files for Iterators
7.2 Iterator Categories
7.2.1 Input Iterators
7.2.2 Output Iterators
7.2.3 Forward Iterators
7.2.4 Bidirectional\Iterational discretionary Iterators
7.2.5 Random Access Iterational discretionary Iteratorstors
7.2.6 The Increment and Decrement Problem of Vector Iterators
7.3 Auxiliary Iterator Functions
7.3.1 Stepping Iterators Using advance()
7.3.2 Processing Iterator Distance Using distance()
7.3.3 Swapping Iterator Values Using iter_swap()
7.4 Iterator Adapters
7.4.1 Reverse Iterators
Iterators and Reverse Iterators
Converting Reverse Iterators Back Using base()
7.4.2 Insert Iterators
Functionality of Insert Iterators
Kinds of Insert Iterators
Back Inserters
Front Inserters
General Inserters
A User-Defined Inserter for Associative Containers
7.4.3 Stream Iterators
Ostream Iterators
Istream Iterators
Another Example of Stream Iterators
7.5 Iterator Traits
7.5.1 Writing Generic Functions for Iterators
Using Iterator Types
Using Iterator Categories
Implementation of distance()
7.5.2 User-Defined Iterators

8 STL Function Objects
8.1 The Concept of Function Objects
8.1.1 Function Objects as Sorting Criteria
8.1.2 Function Objects with Internal State
8.1.3 The Return Value of for_each()
8.1.4 Predicates versus Function Objects
8.2 Predefined Function Objects
8.2.1 Function Adapters
8.2.2 Function Adapters for Member Functions
8.2.3 Function Adapters for Ordinary Functions
8.2.4 User-Defined Function Objects for Function Adapters
8.3 Supplementary Composing Function Objects
8.3.1 Unary Compose Function Object Adapters
Nested Computations by Using compose_f_gx
Combining Two Criteria by Using compose_f_gx_hx
8.3.2 Binary Compose Function Object Adapters

9 STL Algorithms
9.1 Algorithm Header Files
9.2 Algorithm Overview
9.2.1 A Brief Introduction
9.2.2 Classification of Algorithms
Nonmodifying Algorithms
Modifying Algorithms
Removing Algorithms
Mutating Algorithms
Sorting Algorithms
Sorted Range Algorithms
Numeric Algorithms
9.3 Auxiliary Functions
9.4 The for_each() Algorithm
9.5 Nonmodifying Algorithms
9.5.1 Counting Elements
9.5.2 Minimum and Maximum
9.5.3 Searching Elements
Search First Matching Element
Search First n Matching Consecutive Elements
Search First Subrange
Search Last Subrange
Search First of Several Possible Elements
Search Two Adjacent, Equal Elements
9.5.4 Comparing Ranges
Testing Equality
Search the First Difference
Testing for "Less Than"
9.6 Modifying Algorithms
9.6.1 Copying Elements
9.6.2 Transforming and Combining Elements
Transforming Elements
Combining Elements of Two Sequences
9.6.3 Swapping Elements
9.6.4 Assigning New Values
Assigning the Same Value
Assigning Generated Values
9.6.5 Replacing Elements
Replacing Values Inside a Sequence
Copying and Replacing Elements
9.7 Removing Algorithms
9.7.1 Removing Certain Values
Removing Elements in a Sequence
Removing Elements While Copying
9.7.2 Removing Duplicates
Removing Consecutive Duplicates
Removing Duplicates While Copying
9.8 Mutating Algorithms
9.8.1 Reversing the Order of Elements
9.8.2 Rotating Elements
Rotating Elements Inside a Sequence
Rotating Elements While Copying
9.8.3 Permuting Elements
9.8.4 Shuffling Elements
9.8.5 Moving Elements to the Front
9.9 Sorting Algorithms
9.9.1 Sorting All Elements
9.9.2 Partial Sorting
9.9.3 Sorting According to the nth Element
9.9.4 Heap Algorithms
Heap Algorithms in Detail
Example Using Heaps
9.10 Sorted Range Algorithms
9.10.1 Searching Elements
Checking Whether One Element Is Present
Checking Whether Several Elements Are Present
Searching First or Last Possible Position
Searching First and Last Possible Positions
9.10.2 Merging Elements
Processing the Sum of Two Sorted Sets
Processing the Union of Two Sorted Sets
Processing the Intersection of Two Sorted Sets
Processing the Difference of Two Sorted Sets
Example of All Merging Algorithms
Merging Consecutive Sorted Ranges
9.11 Numeric Algorithms
9.11.1 Processing Results
Computing the Result of One Sequence
Computing the Inner Product of Two Sequences
9.11.2 Converting Relative and Absolute Values
Converting Relative Values into Absolute Values
Converting Absolute Values into Relative Values
Example of Converting Relative Values into Absolute Values

10 Special Containers
10.1 Stacks
10.1.1 The Core Interface
10.1.2 Example of Using Stacks
10.1.3 Class stack Type Definitions
Operations
10.1.4 A User-Defined Stack Class
10.2 Queues
10.2.1 The Core Interface
10.2.2 Example of Using Queues
10.2.3 Class queue Type Definitions
Operations
10.2.4 A User-Defined Queue Class
10.3 Priority Queues
10.3.1 The Core Interface
10.3.2 Example of Using Priority Queues
10.3.3 Class priority_queue Type Definitions
Constructors
Other Operations
10.4 Bitsets
10.4.1 Examples of Using Bitsets
Using Bitsets as Set of Flags
Using Bitsets for I/O with Binary Representation
10.4.2 Class bitset in Detail
Create, Copy, and Destroy Operations
Nonmanipulating Operations
Manipulating Operations
Access with Operator _hspace *]
Creating New Modified Bitsets
Operations for Type Conversions
Input/Output Operations

11 Strings
11.1 Motivation
11.1.1 A First Example: Extracting a Temporary File Name
11.1.2 A Second Example: Extracting Words and Printing Them Backward
11.2 Description of the String Classes
11.2.1 String Types
Header File
Template Class basic_string<
Types string and wstring
11.2.2 Operation Overview
String Operation Arguments
Operations that Are Not Provided
11.2.3 Constructors and Destructors
11.2.4 Strings and C-Strings
11.2.5 Size and Capacity
11.2.6 Element Access
11.2.7 Comparisons
11.2.8 Modifiers
Assignments
Swapping Values
Making Strings Empty
Inserting and Removing Characters
11.2.9 Substrings and String Concatenation
11.2.10 Input/Output Operators
11.2.11 Searching and Finding
11.2.12 The Value npos
11.2.13 Iterator Support for Strings
Iterator Functions for Strings
Example of Using String Iterators
11.2.14 Internationalization
11.2.15 Performance
11.2.16 Strings and Vectors
11.3 String Class in Detail
11.3.1 Type Definitions and Static Values
11.3.2 Create, Copy, and Destroy Operations
11.3.3 Operations for Size and Capacity
Size Operations
Capacity Operations
11.3.4 Comparisons
11.3.5 Character Access
11.3.6 Generating C-Strings and Character Arrays
11.3.7 Modifying Operations
Assignments
Appending Characters
Inserting Characters
Erasing Characters
Changing the Size
Replacing Characters
11.3.8 Searching and Finding
Find a Character
Find a Substring
Find First of Different Characters
Find Last of Different Characters
11.3.9 Substrings and String Concatenation
11.3.10 Input/Output Functions
11.3.11 Generating Iterators
11.3.12 Allocator Support

12 Numerics
12.1 Complex Numbers
12.1.1 Examples Using Class Complex
12.1.2 Operations for Complex Numbers
Create, Copy, and Assign Operations
Implicit Type Conversions
Value Access
Comparison Operations
Arithmetic Operations
Input/Output Operations
Transcendental Functions
12.1.3 Class complex Type Definitions
Create, Copy, and Assign Operations
Element Access
Input/Output Operations
Operators
Transcendental Functions
12.2 Valarrays
12.2.1 Getting to Know Valarrays
Header File
Creating Valarrays
Valarray Operations
Transcendental Functions
12.2.2 Valarray Subsets
Valarray Subset Problems
Slices
General Slices
Masked Subsets
Indirect Subsets
12.2.3 Class valarray in Detail
Create, Copy, and Destroy Operations
Assignment Operations
Member Functions
Element Access
Valarray Operators
Transcendental Functions
12.2.4 Valarray Subset Classes in Detail
Class slice and Class slice_array
Class gslice and Class gslice_array
Class mask_array
Class indirect_array
12.3 Global Numeric Functions

13 Input/Output Using Stream Classes
Recent Changes in the IOStream Library
13.1 Common Background of I/O Streams
13.1.1 Stream Objects
13.1.2 Stream Classes
13.1.3 Global Stream Objects
13.1.4 Stream Operators
13.1.5 Manipulators
13.1.6 A Simple Example
13.2 Fundamental Stream Classes and Objects
13.2.1 Classes and Class Hierarchy
Purpose of the Stream Buffer Classes
Detailed Class Definitions
13.2.2 Global Stream Objects
13.2.3 Header Files
13.3 Standard Stream Operators << and
13.3.1 Output Operator <<
13.3.2 Input Operator
13.3.3 Input/Output of Special Types
Type bool
Types char and wchar_t
Type char*
Type void*
Stream Buffers
User-Defined Types
13.4 State of Streams
13.4.1 Constants for the State of Streams
13.4.2 Member Functions Accessing the State of Streams
13.4.3 Stream State and Boolean Conditions
13.4.4 Stream State and Exceptions
13.5 Standard Input/Output Functions
13.5.1 Member Functions for Input
13.5.2 Member Functions for Output
13.5.3 Example Uses
13.6 Manipulators
13.6.1 How Manipulators Work
13.6.2 User-Defined Manipulators
13.7 Formatting
13.7.1 Format Flags
13.7.2 Input/Output Format of Boolean Values
13.7.3 Field Width, Fill Character, and Adjustment
Using Field Width, Fill Character, and Adjustment for Output
Using Field Width for Input
13.7.4 Positive Sign and Uppercase Letters
13.7.5 Numeric Base
13.7.6 Floating-Point Notation
13.7.7 General Formatting Definitions
13.8 Internationalization
13.9 File Access
13.9.1 File Flags
13.9.2 Random Access
13.9.3 Using File Descriptors
13.10 Connecting Input and Output Streams
13.10.1 Loose Coupling Using tie()
13.10.2 Tight Coupling Using Stream Buffers
13.10.3 Redirecting Standard Streams
13.10.4 Streams for Reading and Writing
13.11 Stream Classes for Strings
13.11.1 String Stream Classes
13.11.2 char* Stream Classes
13.12 Input/Output Operators for User-Defined Types
13.12.1 Implementing Output Operators
13.12.2 Implementing Input Operators
13.12.3 Input/Output Using Auxiliary Functions
13.12.4 User-Defined Operators Using Unformatted Functions
13.12.5 User-Defined Format Flags
13.12.6 Conventions for User-Defined Input/Output Operators
13.13 The Stream Buffer Classes
13.13.1 User's View of Stream Buffers
13.13.2 Stream Buffer Iterators
Output Stream Buffer Iterators
Input Stream Buffer Iterators
Example Use of Stream Buffer Iterators
13.13.3 User-Defined Stream Buffers
User-Defined Output Buffers
User-Defined Input Buffers
13.14 Performance Issues
13.14.1 Synchronization with C's Standard Streams
13.14.2 Buffering in Stream Buffers
13.14.3 Using Stream Buffers Directly

14 Internationalization
14.1 Different Character Encodings
14.1.1 Wide-Character and Multibyte Text
14.1.2 Character Traits
14.1.3 Internationalization of Special Characters
14.2 The Concept of Locales
14.2.1 Using Locales
14.2.2 Locale Facets
14.3 Locales in Detail
14.4 Facets in Detail
14.4.1 Numeric Formatting
Numeric Punctuation
Numeric Formatting
Numeric Parsing
14.4.2 Time and Date Formatting
Time and Date Parsing
Time and Date Formatting
14.4.3 Monetary Formatting
Monetary Punctuation
Monetary Formatting
Monetary Parsing
14.4.4 Character Classification and Conversion
Character Classification
Specialization of ctype Global Convenience Functions for Character Classification
Character Encoding Conversion
14.4.5 String Collation
14.4.6 Internationalized Messages

15 Allocators
15.1 Using Allocators as an Application Programmer
15.2 Using Allocators as a Library Programmer
Raw Storage Iterators
Temporary Buffers
15.3 The Default Allocator
15.4 A User-Defined Allocator
15.5 Allocators in Detail
15.5.1 Type Definitions
15.5.2 Operations
15.6 Utilities for Uninitialized Memory in Detail

Internet Resources
Bibliography
Index
Read More Show Less

Preface

In 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 more than 800 pages of facts, figures, and examples. My goal is to describe the C++ Standard Library so that all (or almost all) your programming questions are answered before you think of the question. Note, however, that this is not a complete description of all aspects of the C++ Standard Library. Instead, I present the most important topics necessary for learning and programming in C++by using its standard library.

Each topic is described based on the general concepts;this discussion then leads to the specific details needed to support everyday programming tasks. Specific code examples are provided to help you understand the concepts and the details.

That's it--in a nutshell. I hope you get as much pleasure from reading this book as I did from writing it. Enjoy!

Acknowledgments

This book presents ideas, concepts,solutions, and examples from many sources. In a way it does not seem fair that my name is the only name on the cover. Thus, I'd like to thank all the people and companies who helped and supported me during the past few years.

First, I'd like to thank Dietmar Kuhl. Dietmar is an expert on C++, especially on input/output streams and internationalization (he implemented an I/O stream library just for fun). He not only translated major parts of this book from German to English, he also wrote sections of this book using his expertise. In addition, he provided me with invaluable feedback over the years.

Second, I'd like to thank all the reviewers and everyone else who gave me their opinion. These people endow the book with a quality it would never have had without their input. (Because the list is extensive, please forgive me for any oversight.) The reviewers for the English version of this book included Chuck Allison, Greg Comeau, James A. Crotinger, Gabriel Dos Reis, Alan Ezust, Nathan Meyers, Werner Mossner, Todd Veldhuizen, Chichiang Wan, Judy Ward, and Thomas Wikehult. The German reviewers included Ralf Boecker, Dirk Herrmann, Dietmar Kuhl, Edda Lorke, Herbert Scheubner, Dominik Strasser, and Martin Weitzel. Additional input was provided by Matt Austern, Valentin Bonnard, Greg Colvin, Beman Dawes, Bill Gibbons, Lois Goldthwaite, Andrew Koenig, Steve Rumbsby, Bjarne Stroustrup, and David Vandevoorde.

Special thanks to Dave Abrahams, Janet Cocker, Catherine Ohala, and Maureen Willard who reviewed and edited the whole book very carefully. Their feedback was an incredible contribution to the quality of this book.

A special thanks goes to my "personal living dictionary"--Herb Sutter--the author of the famous "Guru of the Week" (a regular series of C++ programming problems that is published on the comp.std.c++.moderated Internet newsgroup).

I'd also like to thank all the people and companies who gave me the opportunity to test my examples on different platforms with different compilers. Many thanks to Steve Adamczyk, Mike Anderson, and John Spicer from EDG for their great compiler and their support. It was a big help during the standardization process and the writing of this book. Many thanks to P. J. Plauger and Dinkumware, Ltd, for their early standard-conforming implementation of the C++ Standard Library. Many thanks to Andreas Hommel and Metrowerks for an evaluative version of their CodeWarrior Programming Environment. Many thanks to all the developers of the free GNU and egcs compilers. Many thanks to Microsoft for an evaluative version of Visual C++. Many thanks to Roland 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 library implementation.

And, of course many thanks for those who invented, designed, or implemented C++ or parts of the library. Among others are Bjarne Stroustrup, Alexander Stepanov, Meng Lee, Matt Austern, Boris P. Fomichev, and all the other guys who wrote the SGI STL and the STLport.

Many thanks to everyone from Addison Wesley Longman who worked with me. Among others this includes Janet Cocker, Mike Hendrickson, Debbie Lafferty, Marina Lang, Chanda Leary, Catherine Ohala, Marty Rabinowitz, Susanne Spitzer,and Maureen Willard. It was fun.

In addition, I'd 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 and patience (sometimes I ask really silly questions).

Last but not least, many thanks and kisses for my family: Ulli, Lucas, Anica, and Frederic. I definitely did not have enough time for them due to the writing of this book.

Have fun and be human!

About this Book

Soon after its introduction, C++ became a de facto standard in object-oriented programming. This led to the goal of standardization. Only by having a standard, could programs be written that would run on different platforms--from PCs to mainframes. Furthermore, a standard C++ library would enable programmers to use general components and a higher level of abstraction without losing portability, rather than having to develop all code from scratch.

The standardization process was started in 1989 by an international ANSI/ISO committee. It developed the standard based on Bjarne Stroustrup's books (The C++ Programming Language) and (The Annotated C++ Reference Manual). After the standard was completed in 1997,several formal motions by different countries made it an international ISO and ANSI standard in 1998. The standardization process included the development of a C++ Standard Library. The library extends the core language to provide some general components. By using C++'s ability to program new abstract and generic types, the library provides a set of common classes and interfaces. This gives programmers a higher level of abstraction. The library provides the ability to use string types, different data structures (such as dynamic arrays, linked lists, and binary trees), different algorithms (such as different sorting algorithms), numeric classes, input/output (I/O) classes, and classes for internationalization support.

All of these are supported by a fairly simple programming interface. These components are very important for many programs. These days, data processing often means inputting, computing, processing, and outputting large amounts of data, which are often strings.

The library is not self-explanatory. To use these components and to benefit from their power,you need a good introduction that explains the concepts and the important details instead of simply listing the classes and their functions. This book is written exactly for that purpose. First, it introduces the library and all of its components from a conceptional point of view. Next, it describes the details needed for practical programming. Examples are included to demonstrate the exact usage of the components. Thus, this book is a detailed introduction to the C++ library for both the beginner and the practical programmer. Armed with the data provided herein, you should be able to take full advantage of the C++ Standard Library.

Caveat

I don't promise that everything described is easy and self-explanatory. The library provides a lot of flexibility,but flexibility for nontrivial purposes has a price. Beware that the library has traps and pitfalls,which I point out when we encounter them and suggest ways of avoiding them.

What You Should Know Before Reading this Book

To get the most from this book you should already know C++. (The book describes the standard components of C++, but not the language itself.) You should be familiar with the concepts of classes, inheritance,templates, and exception handling. However, you don't have to know all of the minor details about the language. The important details are described in the book (the minor details about the language are more important for people who want to implement the library rather than use it). Note that the language has changed during the standardization process,so your knowledge might not be up to date.

The section on newlang features provides a brief overview and introduction of the latest language features that are important for using the library. You should read this section if you are not sure whether you know all the new features of C++ (such as the keyword {\tt typename} and the concept of namespaces).

Style and Structure of the Book

The C++ Standard Library provides different components that are somewhat but not totally independent of each other,so there is no easy way to describe each part without mentioning others. I considered several different approaches for presenting the contents of this book. One was on the order of the C++ standard. However, this is not the best way to explain the components of the C++ Standard Library from scratch. Another was to start with an overview of all components followed by chapters that provided more details. Alternatively, I could have sorted the components, trying to find an order that had a minimum of cross-references to other sections. My solution was to use a mixture of all three approaches.

I start with a brief introduction of the general concepts and the utilities that are used by the library. Then, I describe all the components, each in one or more chapters. The first component is the standard template library (STL). There is no doubt that the STL is the most powerful, most complex, and most exciting part of 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 next component discussed is one you probably know and use already: the iostreamlib{}. It is followed by a discussion of internationalization, which had some influence on the iostreamlib{}.

Each component description begins with the component's purpose, design, and some examples. Next, a detailed description follows that begins with different ways to use the component, as well as any traps and pitfalls associated with it. The description usually ends with a reference section, in which you can find the exact signature and definition of a component's classes and its functions.

How to Read this Book

This book is a mix of introductory user's guide and structured reference manual regarding the C++ Standard Library. The individual components of the C++ Standard Library are independent of each other, to some extent, so after reading Chapters 2 through 4 you could read the chapters that discuss the individual components in any order. Bear in mind,that Chapters 5 through 9 all describe the same component. To understand the other STL chapters, you should start with the introduction to the STL in chapter 5.

If you are a C++ programmer who wants to know, in general, the concepts and all parts of the library, you could simply read the book from the beginning to the end. However, you should skip the reference sections (which usually are named something like "...{} in detail}"). To program with certain components of the C++ Standard Library, the best way to find something is to use the index. I have tried to make the index very comprehensive to save you time when you are looking for something.

I can't explain all aspects at the same time, so you will find many cross references. It is always a problem to decide whether to follow them. If the cross reference refers to a section that will follow soon, take it as hint that I return to an aspect later. You should follow the cross reference only if you are searching for certain aspects or details and the cross reference seems to lead to details concerning your problem or its solution.

In my experience, the best way to learn something new is to look at examples. Therefore, you'll find a lot of examples throughout the book. They may be a few lines of code or complete programs. In the latter case, you'll find the name of the file containing the program's first comment line. You can find the files on the Internet at my Web site http://www.josuttis.com/libbook/.

State of the Art

While I was writing this book,the C++ standard was completed. Please bear in mind that some compilers might not yet confirm to it. This will most likely change in the near future. As a consequence, you might discover that not all things covered in this book work as described on your system,and you may have to change example programs to fit your specific environment. I can compile almost all example programs with version 2.8 or higher of the EGCS compiler, which is free for almost all platforms and available on the Internet (see http://egcs.cygnus.com/) and on several software CDs.

Example Code and Additional Information

You can access all example programs and acquire more informations about this book and the C++ Standard Library from my Web site at http://www.josuttis.com/libbook/. Please read the {\tt README} file for further details. Also, you can find a lot of additional information about this topic on the Internet. See Internet Resources on page 743 for details.

Feedback

I welcome your feedback (good and bad) on this book. I tried to prepare it carefully; however, I'm human, and at some time I have to stop writing and tweaking. So, you may find some errors, inconsistencies, or subjects that could be described better. Your feedback will give me the chance to improve later

editions. The best way to reach me is by Email: libbook@josuttis.

You can also reach me by phone, fax, or "snail" mail:
Nicolai M. Josuttis Berggarten 9
D--38108
Braunschweig Germany Phone: +49 5309 5747
Fax: +49 5309 5774

Many thanks.

0201379260P04062001

Read More Show Less

Customer Reviews

Be the first to write a review
( 0 )
Rating Distribution

5 Star

(0)

4 Star

(0)

3 Star

(0)

2 Star

(0)

1 Star

(0)

Your Rating:

Your Name: Create a Pen Name or

Barnes & Noble.com Review Rules

Our reader reviews allow you to share your comments on titles you liked, or didn't, with others. By submitting an online review, you are representing to Barnes & Noble.com that all information contained in your review is original and accurate in all respects, and that the submission of such content by you and the posting of such content by Barnes & Noble.com does not and will not violate the rights of any third party. Please follow the rules below to help ensure that your review can be posted.

Reviews by Our Customers Under the Age of 13

We highly value and respect everyone's opinion concerning the titles we offer. However, we cannot allow persons under the age of 13 to have accounts at BN.com or to post customer reviews. Please see our Terms of Use for more details.

What to exclude from your review:

Please do not write about reviews, commentary, or information posted on the product page. If you see any errors in the information on the product page, please send us an email.

Reviews should not contain any of the following:

  • - HTML tags, profanity, obscenities, vulgarities, or comments that defame anyone
  • - Time-sensitive information such as tour dates, signings, lectures, etc.
  • - Single-word reviews. Other people will read your review to discover why you liked or didn't like the title. Be descriptive.
  • - Comments focusing on the author or that may ruin the ending for others
  • - Phone numbers, addresses, URLs
  • - Pricing and availability information or alternative ordering information
  • - Advertisements or commercial solicitation

Reminder:

  • - By submitting a review, you grant to Barnes & Noble.com and its sublicensees the royalty-free, perpetual, irrevocable right and license to use the review in accordance with the Barnes & Noble.com Terms of Use.
  • - Barnes & Noble.com reserves the right not to post any review -- particularly those that do not follow the terms and conditions of these Rules. Barnes & Noble.com also reserves the right to remove any review at any time without notice.
  • - See Terms of Use for other conditions and disclaimers.
Search for Products You'd Like to Recommend

Recommend other products that relate to your review. Just search for them below and share!

Create a Pen Name

Your Pen Name is your unique identity on BN.com. It will appear on the reviews you write and other website activities. Your Pen Name cannot be edited, changed or deleted once submitted.

 
Your Pen Name can be any combination of alphanumeric characters (plus - and _), and must be at least two characters long.

Continue Anonymously
Sort by: Showing all of 5 Customer Reviews
  • Anonymous

    Posted April 21, 2000

    The best book available on the topic

    I looked at many other books on the Standard C++ Library. This was by far the best one. Other books tended to simply list functions in the library. This book explains how and when to use each function or class, points out the traps to avoid, gives many examples, and in general is as much a tutorial as a handbook (just like the title says!).

    1 out of 1 people found this review helpful.

    Was this review helpful? Yes  No   Report this review
  • Posted April 8, 2010

    I Also Recommend:

    A mandatory component of your complete software engineering library

    A handy and reader-friendly book, "The C++ Standard Library: A Tutorial and Reference" delivers on the promise of its title. It is accessible to student developers as well as those new to C++ while still a viable reference for the experienced pro.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted March 14, 2003

    A comprehensive STL book

    This is an excellent book in STL.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted November 8, 2000

    Great Book !!!!!!!

    I've been in data processing for 25 years and programming in numerous languages for 15+ years. I've just stepped up to C++, and I'm more advanced than my fellow college students, even though I'm new to C++. This book as allowed me to 'run' while the other students are crawling.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted February 21, 2000

    Great Book

    Good reference material.

    Was this review helpful? Yes  No   Report this review
Sort by: Showing all of 5 Customer Reviews

If you find inappropriate content, please report it to Barnes & Noble
Why is this product inappropriate?
Comments (optional)