9780201721485

C++ Primer

by ; ;
  • ISBN13:

    9780201721485

  • ISBN10:

    0201721481

  • Edition: 4th
  • Format: Paperback
  • Copyright: 2005-02-14
  • Publisher: Addison-Wesley Professional
  • View Upgraded Edition

Note: Supplemental materials are not guaranteed with Rental or Used book purchases.

Purchase Benefits

  • Free Shipping Icon Free Shipping On Orders Over $35!
    Your order must be $35 or more to qualify for free economy shipping. Bulk sales, PO's, Marketplace items, eBooks and apparel do not qualify for this offer.
  • eCampus.com Logo Get Rewarded for Ordering Your Textbooks! Enroll Now
  • Buyback Icon We Buy This Book Back!
    In-Store Credit: $1.05
    Check/Direct Deposit: $1.00
    PayPal: $1.00
List Price: $59.99 Save up to $53.43
  • Rent Book $21.00
    Add to Cart Free Shipping Icon Free Shipping

    TERM
    PRICE
    DUE
    IN STOCK USUALLY SHIPS IN 24 HOURS.
    *This item is part of an exclusive publisher rental program and requires an additional convenience fee. This fee will be reflected in the shopping cart.

Supplemental Materials

What is included with this book?

Summary

A best-seller completely revised and rewritten to conform to today's C++ usage.

Author Biography

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

Table of Contents

Preface xix
Getting Started
1(30)
Writing a Simple C++ Program
2(3)
Compiling and Executing Our Program
3(2)
A First Look at Input/Output
5(5)
Standard Input and Output Objects
6(1)
A Program that Uses the IO Library
6(4)
A Word About Comments
10(1)
Control Structures
11(9)
The while Statement
12(2)
The for Statement
14(3)
The if Statement
17(1)
Reading an Unknown Number of Inputs
18(2)
Introducing Classes
20(5)
The Sales_item Class
21(3)
A First Look at Member Functions
24(1)
The C++ Program
25(6)
Chapter Summary
28(1)
Defined Terms
28(3)
Part I The Basics
31(272)
Variables and Basic Types
33(44)
Primitive Built-in Types
34(3)
Integral Types
34(3)
Floating-Point Types
37(1)
Literal Constants
37(6)
Variables
43(13)
What Is a Variable?
45(1)
The Name of a Variable
46(2)
Defining Objects
48(2)
Variable Initialization Rules
50(2)
Declarations and Definitions
52(2)
Scope of a Name
54(1)
Define Variables Where They Are Used
55(1)
const Qualifier
56(2)
References
58(3)
Typedef Names
61(1)
Enumerations
62(1)
Class Types
63(4)
Writing Our Own Header Files
67(10)
Designing Our Own Headers
67(2)
A Brief Introduction to the Preprocessor
69(4)
Chapter Summary
73(1)
Defined Terms
73(4)
Library Types
77(32)
Namespace using Declarations
78(2)
Library string Type
80(10)
Defining and Initializing strings
80(1)
Reading and Writing strings
81(2)
Operations on strings
83(5)
Dealing with the Characters of a string
88(2)
Library vector Type
90(5)
Defining and Initializing vectors
91(2)
Operations on vectors
93(2)
Introducing Iterators
95(6)
Iterator Arithmetic
100(1)
Library bitset Type
101(8)
Defining and Initializing bitsets
102(2)
Operations on bitsets
104(3)
Chapter Summary
107(1)
Defined Terms
107(2)
Arrays and Pointers
109(38)
Arrays
110(4)
Defining and Initializing Arrays
110(3)
Operations on Arrays
113(1)
Introducing Pointers
114(16)
What Is a Pointer?
115(1)
Defining and Initializing Pointers
116(3)
Operations on Pointers
119(3)
Using Pointers to Access Array Elements
122(4)
Pointers and the const Qualifier
126(4)
C-Style Character Strings
130(11)
Dynamically Allocating Arrays
134(5)
Interfacing to Older Code
139(2)
Multidimensioned Arrays
141(6)
Pointers and Multidimensioned Arrays
143(2)
Chapter Summary
145(1)
Defined Terms
145(2)
Expressions
147(44)
Arithmetic Operators
149(3)
Relational and Logical Operators
152(2)
The Bitwise Operators
154(5)
Using bitset Objects or Integral Values
156(2)
Using the Shift Operators for IO
158(1)
Assignment Operators
159(3)
Assignment Is Right Associative
160(1)
Assignment Has Low Precedence
160(1)
Compound Assignment Operators
161(1)
Increment and Decrement Operators
162(2)
The Arrow Operator
164(1)
The Conditional Operator
165(2)
The sizeof Operator
167(1)
Comma Operator
168(1)
Evaluating Compound Expressions
168(6)
Precedence
168(2)
Associativity
170(2)
Order of Evaluation
172(2)
The new and delete Expressions
174(4)
Type Conversions
178(13)
When Implicit Type Conversions Occur
179(1)
The Arithmetic Conversions
180(1)
Other Implicit Conversions
181(2)
Explicit Conversions
183(1)
When Casts Might Be Useful
184(1)
Named Casts
184(2)
Old-Style Casts
186(2)
Chapter Summary
188(1)
Defined Terms
188(3)
Statements
191(34)
Simple Statements
192(1)
Declaration Statements
193(1)
Compound Statements (Blocks)
193(1)
Statement Scope
194(1)
The if Statement
195(4)
The if Statement else Branch
197(2)
The switch Statement
199(5)
Using a switch
200(1)
Control Flow within a switch
201(2)
The default Label
203(1)
switch Expression and Case Labels
203(1)
Variable Definitions inside a switch
204(1)
The while Statement
204(3)
The for Loop Statement
207(3)
Omitting Parts of the for Header
209(1)
Multiple Definitions in the for Header
210(1)
The do while Statement
210(2)
The break Statement
212(2)
The continue Statement
214(1)
The goto Statement
214(1)
try Blocks and Exception Handling
215(5)
A throw Expression
216(1)
The try Block
217(2)
Standard Exceptions
219(1)
Using the Preprocessor for Debugging
220(5)
Chapter Summary
223(1)
Defined Terms
223(2)
Functions
225(58)
Defining a Function
226(3)
Function Return Type
227(1)
Function Parameter List
228(1)
Argument Passing
229(16)
Nonreference Parameters
230(2)
Reference Parameters
232(5)
vector and Other Container Parameters
237(1)
Array Parameters
238(3)
Managing Arrays Passed to Functions
241(2)
main: Handling Command-Line Options
243(1)
Functions with Varying Parameters
244(1)
The return Statement
245(6)
Functions with No Return Value
245(1)
Functions that Return a Value
246(3)
Recursion
249(2)
Function Declarations
251(3)
Default Arguments
253(1)
Local Objects
254(2)
Automatic Objects
255(1)
Static Local Objects
255(1)
Inline Functions
256(2)
Class Member Functions
258(7)
Defining the Body of a Member Function
259(2)
Defining a Member Function Outside the Class
261(1)
Writing the Sales_item Constructor
262(2)
Organizing Class Code Files
264(1)
Overloaded Functions
265(11)
Overloading and Scope
268(1)
Function Matching and Argument Conversions
269(1)
The Three Steps in Overload Resolution
270(2)
Argument-Type Conversions
272(4)
Pointers to Functions
276(7)
Chapter Summary
280(1)
Defined Terms
280(3)
The IO Library
283(20)
An Object-Oriented Library
284(3)
Condition States
287(3)
Managing the Output Buffer
290(3)
File Input and Output
293(6)
Using File Stream Objects
293(3)
File Modes
296(3)
A Program to Open and Check Input Files
299(1)
String Streams
299(4)
Chapter Summary
302(1)
Defined Terms
302(1)
Part II Containers and Algorithms
303(124)
Sequential Containers
305(50)
Defining a Sequential Container
307(4)
Initializing Container Elements
307(2)
Constraints on Types that a Container Can Hold
309(2)
Iterators and Iterator Ranges
311(5)
Iterator Ranges
314(1)
Some Container Operations Invalidate Iterators
315(1)
Sequence Container Operations
316(14)
Container Typedefs
316(1)
begin and end Members
317(1)
Adding Elements to a Sequential Container
318(3)
Relational Operators
321(2)
Container Size Operations
323(1)
Accessing Elements
324(2)
Erasing Elements
326(2)
Assignment and swap
328(2)
How a vector Grows
330(3)
capacity and reserve Members
331(2)
Deciding Which Container to Use
333(2)
strings Revisited
335(13)
Other Ways to Construct strings
338(1)
Other Ways to Change a string
339(2)
string-Only Operations
341(2)
string Search Operations
343(3)
Comparing strings
346(2)
Container Adaptors
348(7)
Stack Adaptor
350(1)
Queue and Priority Queue
351(2)
Chapter Summary
353(1)
Defined Terms
353(2)
Associative Containers
355(36)
Preliminaries: the pair Type
356(2)
Associative Containers
358(2)
The map Type
360(12)
Defining a map
360(1)
Types Defined by map
361(1)
Adding Elements to a map
362(1)
Subscripting a map
362(2)
Using map : : insert
364(3)
Finding and Retrieving a map Element
367(1)
Erasing Elements from a map
368(1)
Iterating across a map
369(1)
A Word Transformation Map
369(3)
The set Type
372(3)
Defining and Using sets
373(1)
Building a Word-Exclusion Set
374(1)
The multimap and multiset Types
375(4)
Adding and Removing Elements
376(1)
Finding Elements in a multimap or multiset
376(3)
Using Containers: Text-Query Program
379(12)
Design of the Query Program
380(2)
TextQuery Class
382(1)
Using the TextQuery Class
383(2)
Writing the Member Functions
385(3)
Chapter Summary
388(1)
Defined Terms
388(3)
Generic Algorithms
391(36)
Overview
392(3)
A First Look at the Algorithms
395(10)
Read-Only Algorithms
396(2)
Algorithms that Write Container Elements
398(2)
Algorithms that Reorder Container Elements
400(5)
Revisiting Iterators
405(14)
Insert Iterators
406(1)
iostream Iterators
407(5)
Reverse Iterators
412(3)
const Iterators
415(1)
The Five Iterator Categories
416(3)
Structure of Generic Algorithms
419(2)
Algorithm Parameter Patterns
419(1)
Algorithm Naming Conventions
420(1)
Container-Specific Algorithms
421(6)
Chapter Summary
424(1)
Defined Terms
424(3)
Part III Classes and Data Abstraction
427(128)
Classes
429(46)
Class Definitions and Declarations
430(10)
Class Definitions: A Recap
430(2)
Data Abstraction and Encapsulation
432(2)
More on Class Definitions
434(3)
Class Declarations versus Definitions
437(2)
Class Objects
439(1)
The Implicit this Pointer
440(4)
Class Scope
444(7)
Name Lookup in Class Scope
447(4)
Constructors
451(14)
The Constructor Initializer
453(5)
Default Arguments and Constructors
458(1)
The Default Constructor
458(3)
Implicit Class-Type Conversions
461(3)
Explicit Initialization of Class Members
464(1)
Friends
465(2)
static Class Members
467(8)
static Member Functions
469(1)
static Data Members
469(4)
Chapter Summary
473(1)
Defined Terms
473(2)
Copy Control
475(30)
The Copy Constructor
476(6)
The Synthesized Copy Constructor
479(1)
Defining Our Own Copy Constructor
480(1)
Preventing Copies
481(1)
The Assignment Operator
482(2)
The Destructor
484(2)
A Message-Handling Example
486(6)
Managing Pointer Members
492(13)
Defining Smart Pointer Classes
495(4)
Defining Valuelike Classes
499(3)
Chapter Summary
502(1)
Defined Terms
502(3)
Overloaded Operations and Conversions
505(50)
Defining an Overloaded Operator
506(7)
Overloaded Operator Design
510(3)
Input and Output Operators
513(4)
Overloading the Output Operator<<
513(2)
Overloading the Input Operator>>
515(2)
Arithmetic and Relational Operators
517(3)
Equality Operators
518(2)
Relational Operators
520(1)
Assignment Operators
520(2)
Subscript Operator
522(1)
Member Access Operators
523(3)
Increment and Decrement Operators
526(4)
Call Operator and Function Objects
530(5)
Using Function Objects with Library Algorithms
531(2)
Library-Defined Function Objects
533(2)
Function Adaptors for Function Objects
535(1)
Conversions and Class Types
535(20)
Why Conversions Are Useful
536(1)
Conversion Operators
537(4)
Argument Matching and Conversions
541(3)
Overload Resolution and Class Arguments
544(3)
Overloading, Conversions, and Operators
547(5)
Chapter Summary
552(1)
Defined Terms
552(3)
Part IV Object-Oriented and Generic Programming
555(130)
Object-Oriented Programming
557(66)
OOP: An Overview
558(2)
Defining Base and Derived Classes
560(17)
Defining a Base Class
560(2)
protected Members
562(1)
Derived Classes
563(3)
virtual and Other Member Functions
566(4)
Public, Private, and Protected Inheritance
570(5)
Friendship and Inheritance
575(1)
Inheritance and Static Members
576(1)
Conversions and Inheritance
577(3)
Derived-to-Base Conversions
577(3)
Conversions from Base to Derived
580(1)
Constructors and Copy Control
580(10)
Base-Class Constructors and Copy Control
580(1)
Derived-Class Constructors
581(3)
Copy Control and Inheritance
584(3)
Virtual Destructors
587(2)
Virtuals in Constructors and Destructors
589(1)
Class Scope under Inheritance
590(5)
Name Lookup Happens at Compile Time
590(1)
Name Collisions and Inheritance
591(1)
Scope and Member Functions
592(2)
Virtual Functions and Scope
594(1)
Pure Virtual Functions
595(2)
Containers and Inheritance
597(1)
Handle Classes and Inheritance
598(9)
A Pointerlike Handle
599(3)
Cloning an Unknown Type
602(1)
Using the Handle
603(4)
Text Queries Revisited
607(16)
An Object-Oriented Solution
609(1)
A Valuelike Handle
610(2)
The Query_base Class
612(1)
The Query Handle Class
613(3)
The Derived Classes
616(2)
The eval Functions
618(3)
Chapter Summary
621(1)
Defined Terms
621(2)
Templates and Generic Programming
623(62)
Template Definitions
624(12)
Defining a Function Template
625(2)
Defining a Class Template
627(1)
Template Parameters
628(2)
Template Type Parameters
630(2)
Nontype Template Parameters
632(1)
Writing Generic Programs
633(3)
Instantiation
636(7)
Template Argument Deduction
637(5)
Function-Template Explicit Arguments
642(1)
Template Compilation Models
643(4)
Class Template Members
647(19)
Class-Template Member Functions
651(4)
Template Arguments for Nontype Parameters
655(1)
Friend Declarations in Class Templates
655(3)
Queue and QueueItem Friend Declarations
658(2)
Member Templates
660(4)
The Complete Queue Class
664(1)
static Members of Class Templates
665(1)
A Generic Handle Class
666(5)
Defining the Handle Class
667(1)
Using the Handle
668(3)
Template Specializations
671(8)
Specializing a Function Template
672(3)
Specializing a Class Template
675(2)
Specializing Members but Not the Class
677(1)
Class-Template Partial Specializations
678(1)
Overloading and Function Templates
679(6)
Chapter Summary
683(1)
Defined Terms
683(2)
Part V Advanced Topics
685(124)
Tools for Large Programs
687(66)
Exception Handling
688(24)
Throwing an Exception of Class Type
689(2)
Stack Unwinding
691(2)
Catching an Exception
693(2)
Rethrow
695(1)
The Catch-All Handler
696(1)
Function Try Blocks and Constructors
696(1)
Exception Class Hierarchies
697(3)
Automatic Resource Deallocation
700(2)
The auto_ptr Class
702(4)
Exception Specifications
706(5)
Function Pointer Exception Specifications
711(1)
Namespaces
712(19)
Namespace Definitions
712(5)
Nested Namespaces
717(1)
Unnamed Namespaces
718(2)
Using Namespace Members
720(4)
Classes, Namespaces, and Scope
724(3)
Overloading and Namespaces
727(3)
Namespaces and Templates
730(1)
Multiple and Virtual Inheritance
731(22)
Multiple Inheritance
731(3)
Conversions and Multiple Base Classes
734(3)
Copy Control for Multiply Derived Classes
737(1)
Class Scope under Multiple Inheritance
737(3)
Virtual Inheritance
740(2)
Virtual Base Class Declaration
742(2)
Special Initialization Semantics
744(4)
Chapter Summary
748(1)
Defined Terms
748(5)
Specialized Tools and Techniques
753(56)
Optimizing Memory Allocation
754(18)
Memory Allocation in C++
754(1)
The allocator Class
755(4)
operator new and operator delete Functions
759(2)
Placement new Expressions
761(1)
Explicit Destructor Invocation
762(1)
Class Specific new and delete
763(3)
A Memory-Allocator Base Class
766(6)
Run-Time Type Identification
772(8)
The dynamic_cast Operator
773(2)
The typeid Operator
775(2)
Using RTTI
777(2)
The type_info Class
779(1)
Pointer to Class Member
780(6)
Declaring a Pointer to Member
781(2)
Using a Pointer to Class Member
783(3)
Nested Classes
786(6)
A Nested-Class Implementation
787(4)
Name Lookup in Nested Class Scope
791(1)
Union: A Space-Saving Class
792(4)
Local Classes
796(1)
Inherently Nonportable Features
797(12)
Bit-fields
798(1)
volatile Qualifier
799(2)
Linkage Directives: extern ``C''
801(4)
Chapter Summary
805(1)
Defined Terms
805(4)
Appendix A The Library
809(34)
A.1 Library Names and Headers
810(1)
A.2 A Brief Tour of the Algorithms
811(14)
A.2.1 Algorithms to Find an Object
811(2)
A.2.2 Other Read-Only Algorithms
813(1)
A.2.3 Binary-Search Algorithms
814(1)
A.2.4 Algorithms that Write Container Elements
815(2)
A.2.5 Partitioning and Sorting Algorithms
817(1)
A.2.6 General Reordering Operations
818(2)
A.2.7 Permutation Algorithms
820(1)
A.2.8 Set Algorithms for Sorted Sequences
821(1)
A.2.9 Minimum and Maximum Values
822(1)
A.2.10 Numeric Algorithms
823(2)
A.3 The IO Library Revisited
825(18)
A.3.1 Format State
825(1)
A.3.2 Many Manipulators Change the Format State
825(1)
A.3.3 Controlling Output Formats
826(7)
A.3.4 Controlling Input Formatting
833(1)
A.3.5 Unformatted Input/Output Operations
834(1)
A.3.6 Single-Byte Operations
834(1)
A.3.7 Multi-Byte Operations
835(2)
A.3.8 Random Access to a Stream
837(3)
A.3.9 Reading and Writing to the Same File
840(3)
Index 843

Supplemental Materials

What is included with this book?

The New copy of this book will include any supplemental materials advertised. Please check the title of the book to determine if it should include any access cards, study guides, lab manuals, CDs, etc.

The Used, Rental and eBook copies of this book are not guaranteed to include any supplemental materials. Typically, only the book itself is included. This is true even if the title states it includes any access cards, study guides, lab manuals, CDs, etc.

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 ofC++ Primerto 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 makingprogrammersmore 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 theC++ Primerreflects these new possiblities. Changes to the Fourth Edition In this edition, we have completely reorganized and rewritten theC++ Primerto 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 inbold; important terms that we assume are already familiar to the reader are indicated inbold 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

Rewards Program