Cover image for C++ primer
Title:
C++ primer
Personal Author:
Publication Information:
Upper Saddle River, NJ : Addison-Wesley, 2005
ISBN:
9780201721485

Available:*

Library
Item Barcode
Call Number
Material Type
Item Category 1
Status
Searching...
30000010114426 QA76.73.C153 L56 2005 Open Access Book Book
Searching...

On Order

Summary

Summary

" C++ Primer is well known as one of the best books for learning C++ and is useful for C++ programmers of all skill levels. This Fourth Edition not only keeps this tradition alive, it actually improves on it."
--Steve Vinoski, Chief Engineer, Product Innovation, IONA Technologies

" The Primer really brings this large and complex language down to size."
--Justin Shaw, Senior Member of Technical Staff, Electronic Programs Division, The Aerospace Corporation

"It not only gets novices up and running early, but gets them to do so using good programming practices."
--Nevin ":-)" Liber, Senior Principal Engineer (C++ developer since 1988)

This popular tutorial introduction to standard C++ has been completely updated, reorganized, and rewritten to help programmers learn the language faster and use it in a more modern, effective way.

Just as C++ has evolved since the last edition, so has the authors' approach to teaching it. They now introduce the C++ standard library from the beginning, giving readers the means to write useful programs without first having to master every language detail. Highlighting today's best practices, they show how to write programs that are safe, can be built quickly, and yet offer outstanding performance. Examples that take advantage of the library, and explain the features of C++, also show how to make the best use of the language. As in its previous editions, the book's authoritative discussion of fundamental C++ concepts and techniques makes it a valuable resource even for more experienced programmers.

Program Faster and More Effectively with This Rewritten Classic Restructured for quicker learning, using the C++ standard library Updated to teach the most current programming styles and program design techniques Filled with new learning aids that emphasize important points, warn about common pitfalls, suggest good programming practices, and provide general usage tips Complete with exercises that reinforce skills learned Authoritative and comprehensive in its coverage

The source code for the book's extended examples is available on the Web at the address below.

www.awprofessional.com/cpp_primer


Author Notes

Stanley B. Lippman is Architect with the Visual C++ development team at Microsoft. Previously, he served as a Distinguished Consultant at the Jet Propulsion Laboratories (JPL). Stan spent more than twelve years at Bell Laboratories, where he worked with Bjarne Stroustrup on the original C++ implementation and the Foundation research project. After Bell Laboratories, Stan worked at Disney Feature Animation, originally as principal software engineer, then as software technical director on Fantasia 2000 .

Josée Lajoie is a staff development analyst in the IBM Canada Laboratory C/C++ Compiler group, and is currently the chair of the core language working group for the ANSI/ISO C++ Standard Committee. In addition, she is a regular columnist on the evolution of the C++ Language Standard for the C++ Report..

Barbara E. Moo is an independent consultant with 20 years' experience in the software field. During her nearly 15 years at AT&T, she worked on one of the first commercial products ever written in C++, managed the company's first C++ compiler project, and directed the development of AT&T's award-winning WorldNet Internet service business.



0201721481AB01312005


Excerpts

Excerpts

C++ Primer, Fourth Edition, provides a comprehensive introduction to the C++ language. As a primer, it provides a clear tutorial approach to the language, enhanced by numerous examples and other learning aids. Unlike most primers, it also provides a detailed description of the language, with particular emphasis on current and effective programming techniques. Countless programmers have used previous editions of C++ Primer to learn C++. In that time C++ has matured greatly. Over the years, the focus of the language--and of C++ programmers--has grown beyond a concentration on runtime efficiency to focus on ways of making programmers more efficient. With the widespread availability of the standard library, it is possible to use and learn C++ more effectively than in the past. This revision of the C++ Primer reflects these new possiblities. Changes to the Fourth Edition In this edition, we have completely reorganized and rewritten the C++ Primer to highlight modern styles of C++ programming. This edition gives center stage to using the standard library while deemphasizing techniques for low-level programming. We introduce the standard library much earlier in the text and have reformulated the examples to take advantage of library facilities. We have also streamlined and reordered the presentation of language topics. In addition to restructuring the text, we have incorporated several new elements to enhance the reader's understanding. Each chapter concludes with a Chapter Summary and glossary of Defined Terms, which recap the chapter's most important points. Readers should use these sections as a personal checklist: If you do not understand a term, restudy the corresponding part of the chapter. We've also incorporated a number of other learning aids in the body of the text: Important terms are indicated in bold ; important terms that we assume are already familiar to the reader are indicated in bold italics. Each term appears in the chapter's Defined Terms section. Throughout the book, we highlight parts of the text to call attention to important aspects of the language, warn about common pitfalls, suggest good programming practices, and provide general usage tips. We hope that these notes will help readers more quickly digest important concepts and avoid common pitfalls. To make it easier to follow the relationships among features and concepts, we provide extensive forward and backward cross-references. We have provided sidebar discussions that focus on important concepts and supply additional explanations for topics that programmers new to C++ often find most difficult. Learning any programming language requires writing programs. To that end, the primer provides extensive examples throughout the text. Source code for the extended examples is available on the Web at the following URL: http://www.awprofessional.com/cpp_primer What hasn't changed from earlier versions is that the book remains a compre-hensive tutorial introduction to C++. Our intent is to provide a clear, complete and correct guide to the language. We teach the language by presenting a series of examples, which, in addition to explaining language features, show how to make the best use of C++. Although knowledge of C (the language on which C++ was originally based) is not assumed, we do assume the reader has programmed in a modern block-structured language. Structure of This Book C++ Primer provides an introduction to the International Standard on C++, covering both the language proper and the extensive library that is part of that standard. Much of the power of C++ comes from its support for programming with abstractions. Learning to program effectively in C++ requires more than learning new syntax and semantics. Our focus is on how to use the features of C++ to write programs that are safe, that can be built quickly, and yet offer performance comparable to the sorts of low-level programs often written in C. C++ is a large language and can be daunting to new users. Modern C++ can be thought of as comprising three parts: The low-level language, largely inherited from C More advanced language features that allow us to define our own data types and to organize large-scale programs and systems The standard library, which uses these advanced features to provide a set of useful data structures and algorithms Most texts present C++ in this same order: They start by covering the low-level details and then introduce the more advanced language features. They explain the standard library only after having covered the entire language. The result, all too often, is that readers get bogged down in issues of low-level programming or the complexities of writing type definitions and never really understand the power of programming in a more abstract way. Needless to say, readers also often do not learn enough to build their own abstractions. In this edition we take a completely different tack. We start by covering the basics of the language and the library together. Doing so allows you, the reader, to write significant programs. Only after a thorough grounding in using the library-- and writing the kinds of abstract programs that the library allows--do we move on to those features of C++ that will enable you to write your own abstractions. Parts I and II cover the basic language and library facilities. The focus of these parts is to learn how to write C++ programs and how to use the abstractions from the library. Most C++ programmers need to know essentially everything covered in this portion of the book. In addition to teaching the basics of C++, the material in Parts I and II serves another important purpose. The library facilities are themselves abstract data types written in C++. The library can be defined using the same class-construction features that are available to any C++ programmer. Our experience in teaching C++ is that by first using well-designed abstract types, readers find it easier to understand how to build their own types. Parts III through V focus on how we can write our own types. Part III introduces the heart of C++: its support for classes. The class mechanism provides the basis for writing our own abstractions. Classes are also the foundation for object-oriented and generic programming, which we cover in Part IV. The Primer concludes with Part V, which covers advanced features that are of most use in structuring large, complex systems. 0201721481P01312005 Excerpted from C++ Primer by Stanley B. Lippman, Josée Lajoie, Barbara E. Moo All rights reserved by the original copyright owners. Excerpts are provided for display purposes only and may not be reproduced, reprinted or distributed without the written permission of the publisher.

Table of Contents

Prefacep. xix
Chapter 1 Getting Startedp. 1
1.1 Writing a Simple C++ Programp. 2
1.2 A First Look at Input/Outputp. 5
1.3 A Word About Commentsp. 10
1.4 Control Structuresp. 11
1.5 Introducing Classesp. 20
1.6 The C++ Programp. 25
Chapter Summaryp. 28
Defined Termsp. 28
Part I The Basicsp. 31
Chapter 2 Variables and Basic Typesp. 33
2.1 Primitive Built-in Typesp. 34
2.2 Literal Constantsp. 37
2.3 Variablesp. 43
2.4 const Qualifierp. 56
2.5 Referencesp. 58
2.6 Typedef Namesp. 61
2.7 Enumerationsp. 62
2.8 Class Typesp. 63
2.9 Writing Our Own Header Filesp. 67
Chapter Summaryp. 73
Defined Termsp. 73
Chapter 3 Library Typesp. 77
3.1 Namespace using Declarationsp. 78
3.2 Library string Typep. 80
3.3 Library vector Typep. 90
3.4 Introducing Iteratorsp. 95
3.4.1 Iterator Arithmeticp. 100
3.5 Library bitset Typep. 101
Chapter Summaryp. 107
Defined Termsp. 107
Chapter 4 Arrays and Pointersp. 109
4.1 Arraysp. 110
4.2 Introducing Pointersp. 114
4.3 C-Style Character Stringsp. 130
4.4 Multidimensioned Arraysp. 141
Chapter Summaryp. 145
Defined Termsp. 145
Chapter 5 Expressionsp. 147
5.1 Arithmetic Operatorsp. 149
5.2 Relational and Logical Operatorsp. 152
5.3 The Bitwise Operatorsp. 154
5.4 Assignment Operatorsp. 159
5.5 Increment and Decrement Operatorsp. 162
5.6 The Arrow Operatorp. 164
5.7 The Conditional Operatorp. 165
5.8 The size of Operatorp. 167
5.9 Comma Operatorp. 168
5.10 Evaluating Compound Expressionsp. 168
5.11 The new and delete Expressionsp. 174
5.12 Type Conversionsp. 178
Chapter Summaryp. 188
Defined Termsp. 188
Chapter 6 Statementsp. 191
6.1 Simple Statementsp. 192
6.2 Declaration Statementsp. 193
6.3 Compound Statements (Blocks)p. 193
6.4 Statement Scopep. 194
6.5 The if Statementp. 195
6.5.1 The if Statement else Branchp. 197
6.6 The switch Statementp. 199
6.7 The whileStatementp. 204
6.8 The for Loop Statementp. 207
6.9 The do while Statementp. 210
6.10 The break Statementp. 212
6.11 The continue Statementp. 214
6.12 The goto Statementp. 214
6.13 try Blocks and Exception Handlingp. 215
6.13.1 A throw Expressionp. 216
6.13.2 The try Blockp. 217
6.13.3 Standard Exceptionsp. 219
6.14 Using the Preprocessor for Debuggingp. 220
Chapter Summaryp. 223
Defined Termsp. 223
Chapter 7 Functionsp. 225
7.1 Defining a Functionp. 226
7.2 Argument Passingp. 229
7.3 The return Statementp. 245
7.4 Function Declarationsp. 251
7.5 Local Objectsp. 254
7.6 Inline Functionsp. 256
7.7 ClassMemberFunctionsp. 258
7.8 Overloaded Functionsp. 265
7.9 Pointers to Functionsp. 276
Chapter Summaryp. 280
Defined Termsp. 280
Chapter 8 The IO Libraryp. 283
8.1 An Object-Oriented Libraryp. 284
8.2 Condition Statesp. 287
8.3 Managing the Output Bufferp. 290
8.4 File Input and Outputp. 293
8.5 String Streamsp. 299
Chapter Summaryp. 302
Defined Termsp. 302
Part II Containers and Algorithmsp. 303
Chapter 9 Sequential Containersp. 305
9.1 Defining a Sequential Containerp. 307
9.2 Iterators andIteratorRangesp. 311
9.3 Sequence Container Operationsp. 316
9.4 How a vector Growsp. 330
9.5 Deciding Which Container to Usep. 333
9.6 strings Revisitedp. 335
9.7 Container Adaptorsp. 348
Chapter Summaryp. 353
Defined Termsp. 353
Chapter 10 Associative Containersp. 355
10.1 Preliminaries: the pair Typep. 356
10.2 Associative Containersp. 358
10.3 The map Typep. 360
10.4 The set Typep. 372
10.5 The multimap and multiset Typesp. 375
10.6 Using Containers: Text-Query Programp. 379
Chapter Summaryp. 388
Defined Termsp. 388
Chapter 11 Generic Algorithmsp. 391
11.1 Overviewp. 392
11.2 A First Look at the Algorithmsp. 395
11.3 Revisiting Iteratorsp. 405
11.4 Structure of Generic Algorithmsp. 419
11.5 Container-Specific Algorithmsp. 421
Chapter Summaryp. 424
Defined Termsp. 424
Part III Classes and Data Abstractionp. 427
Chapter 12 Classesp. 429
12.1 Class Definitions and Declarationsp. 430
12.2 The Implicit this Pointerp. 440
12.3 Class Scopep. 444
12.4 Constructorsp. 451
12.5 Friendsp. 465
12.6 static Class Membersp. 467
Chapter Summaryp. 473
Defined Termsp. 473
Chapter 13 Copy Controlp. 475
13.1 The Copy Constructorp. 476
13.2 The Assignment Operatorp. 482
13.3 The Destructorp. 484
13.4 A Message-Handling Examplep. 486
13.5 Managing Pointer Membersp. 492
Chapter Summaryp. 502
Defined Termsp. 502
Chapter 14 Overloaded Operations and Conversionsp. 505
14.1 Defini