Book description
C++ Primer Plus, Sixth Edition
New C++11 Coverage
C++ Primer Plus is a carefully crafted,
complete tutorial on one of the most significant and widely used
programming languages today. An accessible and easy-to-use
self-study guide, this book is appropriate for both serious
students of programming as well as developers already proficient in
other languages.
The sixth edition of C++ Primer Plus has been updated and
expanded to cover the latest developments in C++, including a
detailed look at the new C++11 standard.
Author and educator Stephen Prata has created an introduction to
C++ that is instructive, clear, and insightful. Fundamental
programming concepts are explained along with details of the C++
language. Many short, practical examples illustrate just one or two
concepts at a time, encouraging readers to master new topics by
immediately putting them to use.
Review questions and programming exercises at the end of each
chapter help readers zero in on the most critical information and
digest the most difficult concepts.
In C++ Primer Plus, you’ll find depth, breadth, and a
variety of teaching techniques and tools to enhance your
learning:
A new detailed chapter on the changes and additional capabilities introduced in the C++11 standard
Complete, integrated discussion of both basic C language and additional C++ features
Clear guidance about when and why to use a feature
Hands-on learning with concise and simple examples that develop your understanding a concept or two at a time
Hundreds of practical sample programs
Review questions and programming exercises at the end of each chapter to test your understanding
Coverage of generic C++ gives you the greatest possible flexibility
Teaches the ISO standard, including discussions of templates, the Standard Template Library, the string class, exceptions, RTTI, and namespaces
Table of Contents
1: Getting Started with C++
2: Setting Out to C++
3: Dealing with Data
4: Compound Types
5: Loops and Relational
Expressions
6: Branching Statements and Logical
Operators
7: Functions: C++’s Programming
Modules
8: Adventures in Functions
9: Memory Models and Namespaces
10: Objects and Classes
11: Working with Classes
12: Classes and Dynamic Memory Allocation
13: Class Inheritance
14: Reusing Code in C++
15: Friends, Exceptions, and More
16: The string Class and the Standard Template Library
17: Input, Output, and Files
18: The New C++11 Standard
A Number Bases
B C++ Reserved Words
C The ASCII Character Set
D Operator Precedence
E Other Operators
F The stringTemplate Class
G The Standard Template Library Methods and
Functions
H Selected Readings and Internet
Resources
I Converting to ISO Standard C++
J Answers to Chapter Reviews
Table of contents
- Developer’s Library
- Title Page
- Copyright Page
- Dedication
- Contents at Glance
- Table of Contents
- Acknowledgments
- About the Author
- We Want to Hear from You!
- Reader Services
- Introduction
- 1. Getting Started with C++
-
2. Setting Out to C++
- Features of the main() Function
- C++ Comments
- The C++ Preprocessor and the iostream File
- Header Filenames
- Namespaces
- C++ Output with cout
- C++ Source Code Formatting
- Declaration Statements and Variables
- Assignment Statements
- A New Trick for cout
- Using cin
- Concatenating with cout
- cin and cout: A Touch of Class
- Using a Function That Has a Return Value
- Function Variations
- User-Defined Functions
- Using a User-Defined Function That Has a Return Value
- Placing the using Directive in Multifunction Programs
-
3. Dealing with Data
- Names for Variables
- Integer Types
- The short, int, long, and long long Integer Types
- Unsigned Types
- Choosing an Integer Type
- Integer Literals
- How C++ Decides What Type a Constant Is
- The char Type: Characters and Small Integers
- The bool Type
- Writing Floating-Point Numbers
- Floating-Point Types
- Floating-Point Constants
- Advantages and Disadvantages of Floating-Point Numbers
- Order of Operation: Operator Precedence and Associativity
- Division Diversions
- The Modulus Operator
- Type Conversions
- auto Declarations in C++11
-
4. Compound Types
- Program Notes
- Initialization Rules for Arrays
- C++11 Array Initialization
- Concatenating String Literals
- Using Strings in an Array
- Adventures in String Input
- Reading String Input a Line at a Time
- Mixing String and Numeric Input
- C++11 String Initialization
- Assignment, Concatenation, and Appending
- More string Class Operations
- More on string Class I/O
- Other Forms of String Literals
- Using a Structure in a Program
- C++11 Structure Initialization
- Can a Structure Use a string Class Member?
- Other Structure Properties
- Arrays of Structures
- Bit Fields in Structures
- Setting Enumerator Values
- Value Ranges for Enumerations
- Declaring and Initializing Pointers
- Pointer Danger
- Pointers and Numbers
- Allocating Memory with new
- Freeing Memory with delete
- Using new to Create Dynamic Arrays
- Program Notes
- Summarizing Pointer Points
- Pointers and Strings
- Using new to Create Dynamic Structures
- Automatic Storage, Static Storage, and Dynamic Storage
- The vector Template Class
- The array Template Class (C++11)
- Comparing Arrays, Vector Objects, and Array Objects
-
5. Loops and Relational Expressions
- Parts of a for Loop
- Back to the for Loop
- Changing the Step Size
- Inside Strings with the for Loop
- The Increment (++) and Decrement (--) Operators
- Side Effects and Sequence Points
- Prefixing Versus Postfixing
- The Increment/Decrement Operators and Pointers
- Combination Assignment Operators
- Compound Statements, or Blocks
- More Syntax Tricks—The Comma Operator
- Relational Expressions
- Assignment, Comparison, and a Mistake You’ll Probably Make
- Comparing C-Style Strings
- Comparing string Class Strings
- Program Notes
- for Versus while
- Just a Moment—Building a Time-Delay Loop
- Using Unadorned cin for Input
- cin.get(char) to the Rescue
- Which cin.get() Should You Use?
- The End-of-File Condition
- Yet Another Version of cin.get()
- Initializing a Two-Dimensional Array
- Using a Two-Dimensional Array
-
6. Branching Statements and Logical Operators
- The if else Statement
- Formatting if else Statements
- The if else if else Construction
- The Logical OR Operator: ||
- The Logical AND Operator: &&
- Setting Up Ranges with &&
- The Logical NOT Operator: !
- Logical Operator Facts
- Alternative Representations
- Using Enumerators as Labels
- switch and if else
- Program Notes
- Program Notes
- Text I/O and Text Files
- Writing to a Text File
- Reading from a Text File
-
7. Functions: C++’s Programming Modules
- Defining a Function
- Prototyping and Calling a Function
- Multiple Arguments
- Another Two-Argument Function
- How Pointers Enable Array-Processing Functions
- The Implications of Using Arrays as Arguments
- More Array Function Examples
- Functions Using Array Ranges
- Pointers and const
- Functions with C-Style String Arguments
- Functions That Return C-Style Strings
- Passing and Returning Structures
- Another Example of Using Functions with Structures
- Passing Structure Addresses
- Program Notes
- Recursion with a Single Recursive Call
- Recursion with Multiple Recursive Calls
- Function Pointer Basics
- A Function Pointer Example
- Variations on the Theme of Function Pointers
- Simplifying with typedef
-
8. Adventures in Functions
- Creating a Reference Variable
- References as Function Parameters
- Reference Properties and Oddities
- Using References with a Structure
- Using References with a Class Object
- Another Object Lesson: Objects, Inheritance, and References
- When to Use Reference Arguments
- Program Notes
- An Overloading Example
- When to Use Function Overloading
- Overloaded Templates
- Template Limitations
- Explicit Specializations
- Instantiations and Specializations
- Which Function Version Does the Compiler Pick?
- Template Function Evolution
-
9. Memory Models and Namespaces
- Scope and Linkage
- Automatic Storage Duration
- Static Duration Variables
- Static Duration, External Linkage
- Static Duration, Internal Linkage
- Static Storage Duration, No Linkage
- Specifiers and Qualifiers
- Functions and Linkage
- Language Linking
- Storage Schemes and Dynamic Allocation
- Traditional C++ Namespaces
- New Namespace Features
- A Namespace Example
- Namespaces and the Future
-
10. Objects and Classes
- What Is a Type?
- Classes in C++
- Implementing Class Member Functions
- Using Classes
- Changing the Implementation
- Reviewing Our Story to Date
- Declaring and Defining Constructors
- Using Constructors
- Default Constructors
- Destructors
- Improving the Stock Class
- Constructors and Destructors in Review
- Class Scope Constants
- Scoped Enumerations (C++11)
-
11. Working with Classes
- Adding an Addition Operator
- Overloading Restrictions
- More Overloaded Operators
- Creating Friends
- A Common Kind of Friend: Overloading the << Operator
- Using a State Member
- Overloading Arithmetic Operators for the Vector Class
- An Implementation Comment
- Taking the Vector Class on a Random Walk
- Program Notes
- Conversion Functions
- Conversions and Friends
-
12. Classes and Dynamic Memory Allocation
- A Review Example and Static Class Members
- Special Member Functions
- Back to Stringbad: Where the Copy Constructor Goes Wrong
- More Stringbad Problems: Assignment Operators
- The Revised Default Constructor
- Comparison Members
- Accessing Characters by Using Bracket Notation
- Static Class Member Functions
- Further Assignment Operator Overloading
- Don’ts and Dos
- Memberwise Copying for Classes with Class Members
- Returning a Reference to a const Object
- Returning a Reference to a Non-const Object
- Returning an Object
- Returning a const Object
- Looking Again at new and delete
- Pointers and Objects Summary
- Looking Again at Placement new
- Overloading the << Operator
- Conversion Functions
- Classes Whose Constructors Use new
- A Queue Class
- The Customer Class
- The ATM Simulation
-
13. Class Inheritance
- Deriving a Class
- Constructors: Access Considerations
- Using a Derived Class
- Special Relationships Between Derived and Base Classes
- Developing the Brass and BrassPlus Classes
- Pointer and Reference Type Compatibility
- Virtual Member Functions and Dynamic Binding
- Things to Know About Virtual Methods
- Applying the ABC Concept
- ABC Philosophy
- Case 1: Derived Class Doesn’t Use new
- Case 2: Derived Class Does Use new
- An Inheritance Example with Dynamic Memory Allocation and Friends
- Member Functions That the Compiler Generates for You
- Other Class Method Considerations
- Public Inheritance Considerations
- Class Function Summary
-
14. Reusing Code in C++
- The valarray Class: A Quick Look
- The Student Class Design
- The Student Class Example
- A New Version of the Student Class Example
- Containment or Private Inheritance?
- Protected Inheritance
- Redefining Access with using
- How Many Workers?
- Which Method?
- Multiple Inheritance Synopsis
- Defining a Class Template
- Using a Template Class
- A Closer Look at the Template Class
- An Array Template Example and Non-Type Arguments
- Template Versatility
- Template Specializations
- Member Templates
- Templates As Parameters
- Template Classes and Friends
- Template Aliases (C++11)
-
15. Friends, Exceptions, and More
- Friend Classes
- Friend Member Functions
- Other Friendly Relationships
- Shared Friends
- Nested Classes and Access
- Nesting in a Template
- Calling abort()
- Returning an Error Code
- The Exception Mechanism
- Using Objects as Exceptions
- Exception Specifications Meet C++11
- Unwinding the Stack
- More Exception Features
- The exception Class
- Exceptions, Classes, and Inheritance
- When Exceptions Go Astray
- Exception Cautions
- What Is RTTI For?
- How Does RTTI Work?
- Misusing RTTI
-
16. The string Class and the Standard Template Library
- Constructing a String
- The string Class Input
- Working with Strings
- What Else Does the string Class Offer?
- String Varieties
- Using Smart Pointers
- Smart Pointer Considerations
- Why unique_ptr Is Better than auto_ptr
- Selecting a Smart Pointer
- The vector Template Class
- Things to Do to Vectors
- More Things to Do to Vectors
- The Range-Based for Loop (C++11)
- Why Iterators?
- Kinds of Iterators
- Iterator Hierarchy
- Concepts, Refinements, and Models
- Kinds of Containers
- Associative Containers
- Unordered Associative Containers (C++11)
- Functor Concepts
- Predefined Functors
- Adaptable Functors and Function Adapters
- Algorithm Groups
- General Properties of Algorithms
- The STL and the string Class
- Functions Versus Container Methods
- Using the STL
- vector, valarray, and array
- The initializer_list Template (C++11)
- Using initializer_list
- Program Notes
-
17. Input, Output, and Files
- Streams and Buffers
- Streams, Buffers, and the iostream File
- Redirection
- The Overloaded << Operator
- The Other ostream Methods
- Flushing the Output Buffer
- Formatting with cout
- How cin >> Views Input
- Stream States
- Other istream Class Methods
- Other istream Methods
- Simple File I/O
- Stream Checking and is_open()
- Opening Multiple Files
- Command-Line Processing
- File Modes
- Random Access
-
18. Visiting with the New C++ Standard
- New Types
- Uniform Initialization
- Declarations
- nullptr
- Smart Pointers
- Exception Specification Changes
- Scoped Enumerations
- Class Changes
- Template and STL Changes
- The rvalue Reference
- The Need for Move Semantics
- A Move Example
- Move Constructor Observations
- Assignment
- Forcing a Move
- Special Member Functions
- Defaulted and Deleted Methods
- Delegating Constructors
- Inheriting Constructors
- Managing Virtual Methods: override and final
- The How of Function Pointers, Functors, and Lambdas
- The Why of Lambdas
- The function Wrapper and Template Inefficiencies
- Fixing the Problem
- Further Options
- Template and Function Parameter Packs
- Unpacking the Packs
- Using Recursion in Variadic Template Functions
- Concurrent Programming
- Library Additions
- Low-Level Programming
- Miscellaneous
- The Boost Project
- The TR1
- Using Boost
-
Appendixes
- A. Number Bases
- B. C++ Reserved Words
- C. The ASCII Character Set
- D. Operator Precedence
- E. Other Operators
-
F. The string Template Class
- Default Constructor
- Constructors That Use C-Style Strings
- Constructors That Use Part of a C-Style String
- Constructors That Use an Lvalue Reference
- Constructors That Use an Rvalue Reference (C++11)
- Constructor That Uses n Copies of a Character
- Constructor That Uses a Range
- Constructor That Uses an Initialization List (C++11)
- Memory Miscellany
- The find() Family
- The rfind() Family
- The find_first_of() Family
- The find_last_of() Family
- The find_first_not_of() Family
- The find_last_not_of() Family
- Methods for Appending and Adding
- More Assignment Methods
- Insertion Methods
- Erase Methods
- Replacement Methods
- Other Modifying Methods: copy() and swap()
- G. The Standard Template Library Methods and Functions
- H. Selected Readings and Internet Resources
- I. Converting to ISO Standard C++
- J. Answers to Chapter Reviews
- Index
- Footnotes
Product information
- Title: C++ Primer Plus
- Author(s):
- Release date: October 2011
- Publisher(s): Addison-Wesley Professional
- ISBN: 9780132781145
You might also like
book
C++ In a Nutshell
To-the-point, authoritative, no-nonsense solutions have always been a trademark of O'Reilly books. The In a Nutshell …
book
Advanced C++
Become an expert at C++ by learning all the key C++ concepts and working through interesting …
video
Beginning C++
C++ is a powerful high-level language with a wealth of recently added features that enhance its …
book
Mastering C++ Programming
Take your C++ coding to the next level by leveraging the latest features and advanced techniques …