C++ Standard Library, The: A Tutorial and Reference
The Best-Selling C++ Resource

Now Updated for C++11

 

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: A Tutorial and Reference, Second Edition, describes this library as now incorporated into the new ANSI/ISO C++ language standard (C++11). The book provides comprehensive documentation of each library component, including an introduction to its purpose and design; clearly written explanations of complex concepts; the practical programming details needed for effective use; traps and pitfalls; the exact signature and definition of the most important classes and functions; and numerous examples of working code. The book focuses in particular on the Standard Template Library (STL), examining containers, iterators, function objects, and STL algorithms.

 

The book covers all the new C++11 library components, including

 

  • Concurrency
  • Fractional arithmetic
  • Clocks and timers
  • Tuples
  • New STL containers
  • New STL algorithms
  • New smart pointers
  • New locale facets
  • Random numbers and distributions
  • Type traits and utilities
  • Regular expressions

 

The book also examines the new C++ programming style and its effect on the standard library, including lambdas, range-based for  loops, move semantics, and variadic templates.

 

An accompanying Web site, including source code, can be found at www.cppstdlib.com.

 

1138611874
C++ Standard Library, The: A Tutorial and Reference
The Best-Selling C++ Resource

Now Updated for C++11

 

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: A Tutorial and Reference, Second Edition, describes this library as now incorporated into the new ANSI/ISO C++ language standard (C++11). The book provides comprehensive documentation of each library component, including an introduction to its purpose and design; clearly written explanations of complex concepts; the practical programming details needed for effective use; traps and pitfalls; the exact signature and definition of the most important classes and functions; and numerous examples of working code. The book focuses in particular on the Standard Template Library (STL), examining containers, iterators, function objects, and STL algorithms.

 

The book covers all the new C++11 library components, including

 

  • Concurrency
  • Fractional arithmetic
  • Clocks and timers
  • Tuples
  • New STL containers
  • New STL algorithms
  • New smart pointers
  • New locale facets
  • Random numbers and distributions
  • Type traits and utilities
  • Regular expressions

 

The book also examines the new C++ programming style and its effect on the standard library, including lambdas, range-based for  loops, move semantics, and variadic templates.

 

An accompanying Web site, including source code, can be found at www.cppstdlib.com.

 

75.99 In Stock
C++ Standard Library, The: A Tutorial and Reference

C++ Standard Library, The: A Tutorial and Reference

by Nicolai Josuttis
C++ Standard Library, The: A Tutorial and Reference

C++ Standard Library, The: A Tutorial and Reference

by Nicolai Josuttis

eBook

$75.99 

Available on Compatible NOOK devices, the free NOOK App and in My Digital Library.
WANT A NOOK?  Explore Now

Related collections and offers


Overview

The Best-Selling C++ Resource

Now Updated for C++11

 

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: A Tutorial and Reference, Second Edition, describes this library as now incorporated into the new ANSI/ISO C++ language standard (C++11). The book provides comprehensive documentation of each library component, including an introduction to its purpose and design; clearly written explanations of complex concepts; the practical programming details needed for effective use; traps and pitfalls; the exact signature and definition of the most important classes and functions; and numerous examples of working code. The book focuses in particular on the Standard Template Library (STL), examining containers, iterators, function objects, and STL algorithms.

 

The book covers all the new C++11 library components, including

 

  • Concurrency
  • Fractional arithmetic
  • Clocks and timers
  • Tuples
  • New STL containers
  • New STL algorithms
  • New smart pointers
  • New locale facets
  • Random numbers and distributions
  • Type traits and utilities
  • Regular expressions

 

The book also examines the new C++ programming style and its effect on the standard library, including lambdas, range-based for  loops, move semantics, and variadic templates.

 

An accompanying Web site, including source code, can be found at www.cppstdlib.com.

 


Product Details

ISBN-13: 9780132977739
Publisher: Pearson Education
Publication date: 05/25/2012
Sold by: Barnes & Noble
Format: eBook
Pages: 1136
File size: 88 MB
Note: This product may take a few minutes to download.
Age Range: 18 Years

About the Author

Nicolai M. Josuttis is an independent technical consultant who designs mid-sized and large software systems for the telecommunication, traffic, finance, and manufacturing industries. A former member of the C++ Standard Committee library working group, he is well known in the programming community for his authoritative books. In addition to The C++ Standard Library, a worldwide best-seller since its first publication in 1999, his books include C++ Templates: The Complete Guide (with David Vandevoorde, Addison-Wesley, 2003) and SOA in Practice: The Art of Distributed System Design (O’Reilly Media, 2007).

 

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.

Table of Contents

Preface to the Second Edition xxiii

Acknowledgments for the Second Edition xxiv

Preface to the First Edition xxv

Acknowledgments for the First Edition xxvi

 

Chapter 1: About This Book 1

1.1 Why This Book 1

1.2 Before Reading This Book 2

1.3 Style and Structure of the Book 2

1.4 How to Read This Book 4

1.5 State of the Art 5

1.6 Example Code and Additional Information 5

1.7 Feedback 5

 

Chapter 2: Introduction to C++ and the Standard Library 7

2.1 History of the C++ Standards 7

2.2 Complexity and Big-O Notation 10

 

Chapter 3: New Language Features 13

3.1 New C++11 Language Features 13

3.2 Old “New” Language Features 33

 

Chapter 4: General Concepts 39

4.1 Namespace std 39

4.2 Header Files 40

4.3 Error and Exception Handling 41

4.4 Callable Objects 54

4.5 Concurrency and Multithreading 55

4.6 Allocators 57

 

Chapter 5: Utilities 59

5.1 Pairs and Tuples 60

5.2 Smart Pointers 76

5.3 Numeric Limits 115

5.4 Type Traits and Type Utilities 122

5.5 Auxiliary Functions 134

5.6 Compile-Time Fractional Arithmetic with Class ratio<> 140

5.7 Clocks and Timers 143

5.8 Header Files <cstddef>, <cstdlib>, and <cstring> 161

 

Chapter 6: The Standard Template Library 165

6.1 STL Components 165

6.2 Containers 167

6.3 Iterators 188

6.4 Algorithms 199

6.5 Iterator Adapters 210

6.6 User-Defined Generic Functions 216

6.7 Manipulating Algorithms 217

6.8 Functions as Algorithm Arguments 224

6.9 Using Lambdas 229

6.10 Function Objects 233

6.11 Container Elements 244

6.12 Errors and Exceptions inside the STL 245

6.13 Extending the STL 250

 

Chapter 7: STL Containers 253

7.1 Common Container Abilities and Operations 254

7.2 Arrays 261

7.3 Vectors 270

7.4 Deques 283

7.5 Lists 290

7.6 Forward Lists 300

7.7 Sets and Multisets 314

7.8 Maps and Multimaps 331

7.9 Unordered Containers 355

7.10 Other STL Containers 385

7.11 Implementing Reference Semantics 388

7.12 When to Use Which Container 392

 

Chapter 8: STL Container Members in Detail 397

8.1 Type Definitions 397

8.2 Create, Copy, and Destroy Operations 400

8.3 Nonmodifying Operations 403

8.4 Assignments 406

8.5 Direct Element Access 408

8.6 Operations to Generate Iterators 410

8.7 Inserting and Removing Elements 411

8.8 Special Member Functions for Lists and Forward Lists 420

8.9 Container Policy Interfaces 427

8.10 Allocator Support 430

 

Chapter 9: STL Iterators 433

9.1 Header Files for Iterators 433

9.2 Iterator Categories 433

9.3 Auxiliary Iterator Functions 441

9.4 Iterator Adapters 448

9.5 Iterator Traits 466

9.6 Writing User-Defined Iterators 471

 

Chapter 10: STL Function Objects and Using Lambdas 475

10.1 The Concept of Function Objects 475

10.2 Predefined Function Objects and Binders 486

10.3 Using Lambdas 499

 

Chapter 11: STL Algorithms 505

11.1 Algorithm Header Files 505

11.2 Algorithm Overview 505

11.3 Auxiliary Functions 517

11.4 The for_each() Algorithm 519

11.5 Nonmodifying Algorithms 524

11.6 Modifying Algorithms 557

11.7 Removing Algorithms 575

11.8 Mutating Algorithms 583

11.9 Sorting Algorithms 596

11.10 Sorted-Range Algorithms 608

11.11 Numeric Algorithms 623

 

Chapter 12: Special Containers 631

12.1 Stacks 632

12.2 Queues 638

12.3 Priority Queues 641

12.4 Container Adapters in Detail 645

12.5 Bitsets 650

 

Chapter 13: Strings 655

13.1 Purpose of the String Classes 656

13.2 Description of the String Classes 663

13.3 String Class in Detail 693

 

Chapter 14: Regular Expressions 717

14.1 The Regex Match and Search Interface 717

14.2 Dealing with Subexpressions 720

14.3 Regex Iterators 726

14.4 Regex Token Iterators 727

14.5 Replacing Regular Expressions 730

14.6 Regex Flags 732

14.7 Regex Exceptions 735

14.8 The Regex ECMA Script Grammar 738

14.9 Other Grammars 739

14.10 Basic Regex Signatures in Detail 740

 

Chapter 15: Input/Output Using Stream Classes 743

15.1 Common Background of I/O Streams 744

15.2 Fundamental Stream Classes and Objects 748

15.3 Standard Stream Operators << and >> 753

15.4 State of Streams 758

15.5 Standard Input/Output Functions 767

15.6 Manipulators 774

15.7 Formatting 779

15.8 Internationalization 790

15.9 File Access 791

15.10 Stream Classes for Strings 802

15.11 Input/Output Operators for User-Defined Types 810

15.12 Connecting Input and Output Streams 819

15.13 The Stream Buffer Classes 826

15.14 Performance Issues 844

 

Chapter 16: Internationalization 849

16.1 Character Encodings and Character Sets 850

16.2 The Concept of Locales 857

16.3 Locales in Detail 866

16.4 Facets in Detail 869

 

Chapter 17: Numerics 907

17.1 Random Numbers and Distributions 907

17.2 Complex Numbers 925

17.3 Global Numeric Functions 941

17.4 Valarrays 943

 

Chapter 18: Concurrency 945

18.1 The High-Level Interface: async() and Futures 946

18.2 The Low-Level Interface: Threads and Promises 964

18.3 Starting a Thread in Detail 973

18.4 Synchronizing Threads, or the Problem of Concurrency 982

18.5 Mutexes and Locks 989

18.6 Condition Variables 1003

18.7 Atomics 1012

 

Chapter 19: Allocators 1023

19.1 Using Allocators as an Application Programmer 1023

19.2 A User-Defined Allocator 1024

19.3 Using Allocators as a Library Programmer 1026

 

Bibliography 1031

Index 1037

 

Preface

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? 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 thankallthe 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 ...

From the B&N Reads Blog

Customer Reviews