You are previewing Sams Teach Yourself C++ in One Hour a Day, Seventh Edition.
O'Reilly logo
Sams Teach Yourself C++ in One Hour a Day, Seventh Edition

Book Description

Learn C++ in Just One Hour a Day

Completely updated for the C++11 standard, Sams Teach Yourself C++ in One Hour a Day presents the language from a practical point of view, helping you learn how to use C++11 to create faster, simpler, and more efficient C++ applications.

  • Master the fundamentals of C++ and object-oriented programming

  • Understand how C++11 features help you write compact and efficient code using concepts such as lambda expressions, move constructors, and assignment operators

  • Learn the Standard Template Library, including containers and algorithms used in most real-world C++ applications

  • Test your knowledge and expertise using exercises at the end of every lesson

  • Learn on your own time, at your own pace:

  • No previous programming experience required

  • Learn C++11, object-oriented programming, and analysis

  • Write fast and powerful C++ programs, compile the source code with a gcc compiler, and create executable files

  • Use the Standard Template Library’s (STL) algorithms and containers to write feature-rich yet stable C++ applications

  • Develop sophisticated programming techniques using lambda expressions, smart pointers, and move constructors

  • Learn to expand your program’s power with inheritance and polymorphism

  • Master the features of C++ by learning from programming experts

  • Learn C++11 features that allow you to program compact and high-performance C++ applications

  • TABLE OF CONTENTS

    PART I: THE BASICS

    LESSON 1: Getting Started with C++11

    LESSON 2: The Anatomy of a C++ Program

    LESSON 3: Using Variables, Declaring Constants

    LESSON 4: Managing Arrays and Strings

    LESSON 5: Working with Expressions, Statements, and Operators

    LESSON 6: Controlling Program Flow

    LESSON 7: Organizing Code with Functions

    LESSON 8: Pointers and References Explained

    PART II: FUNDAMENTALS OF OBJECT-ORIENTED C++ PROGRAMMING

    LESSON 9: Classes and Objects

    LESSON 10: Implementing Inheritance

    LESSON 11: Polymorphism

    LESSON 12: Operator Types and Operator Overloading

    LESSON 13: Casting Operators

    LESSON 14: An Introduction to Macros and Templates

    PART III: LEARNING THE STANDARD TEMPLATE LIBRARY (STL)

    LESSON 15: An Introduction to the Standard Template Library

    LESSON 16: The STL String Class
    LESSON 17: STL Dynamic Array Classes
    LESSON 18: STL list and forward_list
    LESSON 19: STL Set Classes
    LESSON 20: STL Map Classes

    PART IV: MORE STL

    LESSON 21: Understanding Function Objects

    LESSON 22: C++11 Lambda Expressions
    LESSON 23: STL Algorithms
    LESSON 24: Adaptive Containers: Stack and Queue
    LESSON 25: Working with Bit Flags Using STL

    PART V: ADVANCED C++ CONCEPTS

    LESSON 26: Understanding Smart Pointers

    LESSON 27: Using Streams for Input and Output
    LESSON 28: Exception Handling
    LESSON 29: Going Forward

    APPENDIXES

    A: Working with Numbers: Binary and Hexadecimal

    B: C++ Keywords

    C: Operator Precedence

    D: Answers

    E: ASCII Codes

    Table of Contents

    1. Title Page
    2. Copyright Page
    3. Contents at a Glance
    4. Table of Contents
    5. About the Author
    6. Dedication
    7. Acknowledgments
    8. We Want to Hear from You!
    9. Reader Services
    10. Introduction
      1. Who Should Read This Book?
      2. Organization of This Book
      3. Conventions Used in This Book
      4. Sample Code for this Book
    11. Part I. The Basics
      1. Lesson 1. Getting Started
        1. A Brief History of C++
        2. Programming a C++ Application
        3. What’s New in C++11
        4. Summary
        5. Q&A
        6. Workshop
      2. Lesson 2. The Anatomy of a C++ Program
        1. Part of the Hello World Program
        2. The Concept of Namespaces
        3. Comments in C++ Code
        4. Functions in C++
        5. Basic Input Using std::cin and Output Using std::cout
        6. Summary
        7. Q&A
        8. Workshop
      3. Lesson 3. Using Variables, Declaring Constants
        1. What Is a Variable?
        2. Common Compiler-Supported C++ Variable Types
        3. Determining the Size of a Variable Using sizeof
        4. Using typedef to Substitute a Variable’s Type
        5. What Is a Constant?
        6. Naming Variables and Constants
        7. Keywords You Cannot Use as Variable or Constant Names
        8. Summary
        9. Q&A
        10. Workshop
      4. Lesson 4. Managing Arrays and Strings
        1. What Is an Array?
        2. Multidimensional Arrays
        3. Dynamic Arrays
        4. C-style Strings
        5. C++ Strings: Using std::string
        6. Summary
        7. Q&A
        8. Workshop
      5. Lesson 5. Working with Expressions, Statements, and Operators
        1. Statements
        2. Compound Statements or Blocks
        3. Using Operators
        4. Summary
        5. Q&A
        6. Workshop
      6. Lesson 6. Controlling Program Flow
        1. Conditional Execution Using if ... else
        2. Getting Code to Execute in Loops
        3. Modifying Loop Behavior Using continue and break
        4. Programming Nested Loops
        5. Summary
        6. Q&A
        7. Workshop
      7. Lesson 7. Organizing Code with Functions
        1. The Need for Functions
        2. Using Functions to Work with Different Forms of Data
        3. How Function Calls Are Handled by the Microprocessor
        4. Summary
        5. Q&A
        6. Workshop
      8. Lesson 8. Pointers and References Explained
        1. What Is a Pointer?
        2. Dynamic Memory Allocation
        3. Common Programming Mistakes When Using Pointers
        4. Pointer Programming Best-Practices
        5. What Is a Reference?
        6. Summary
        7. Q&A
        8. Workshop
    12. Part II. Fundamentals of Object-Oriented C++ Programming
      1. Lesson 9. Classes and Objects
        1. The Concept of Classes and Objects
        2. Keywords public and private
        3. Constructors
        4. Destructor
        5. Copy Constructor
        6. Different Uses of Constructors and Destructor
        7. this Pointer
        8. sizeof() a Class
        9. How struct Differs from class
        10. Declaring a friend of a class
        11. Summary
        12. Q&A
        13. Workshop
      2. Lesson 10. Implementing Inheritance
        1. Basics of Inheritance
        2. Private Inheritance
        3. Protected Inheritance
        4. The Problem of Slicing
        5. Multiple Inheritance
        6. Summary
        7. Q&A
        8. Workshop
      3. Lesson 11. Polymorphism
        1. Basics of Polymorphism
        2. Using virtual Inheritance to Solve the Diamond Problem
        3. Virtual Copy Constructors?
        4. Summary
        5. Q&A
        6. Workshop
      4. Lesson 12. Operator Types and Operator Overloading
        1. What Are Operators in C++?
        2. Unary Operators
        3. Binary Operators
        4. Function Operator ()
        5. Operators That Cannot Be Overloaded
        6. Summary
        7. Q&A
        8. Workshop
      5. Lesson 13. Casting Operators
        1. The Need for Casting
        2. Why C-Style Casts Are Not Popular with Some C++ Programmers
        3. The C++ Casting Operators
        4. Problems with the C++ Casting Operators
        5. Summary
        6. Q&A
        7. Workshop
      6. Lesson 14. An Introduction to Macros and Templates
        1. The Preprocessor and the Compiler
        2. Using #define Macros to Define Constants
        3. Using #define To Write Macro Functions
        4. An Introduction to Templates
        5. Summary
        6. Q&A
        7. Workshop
    13. Part III. Learning the Standard Template Library (STL)
      1. Lesson 15. An Introduction to the Standard Template Library
        1. STL Containers
        2. STL Iterators
        3. STL Algorithms
        4. The Interaction Between Containers and Algorithms Using Iterators
        5. STL String Classes
        6. Summary
        7. Q&A
        8. Workshop
      2. Lesson 16. The STL String Class
        1. The Need for String Manipulation Classes
        2. Working with the STL String Class
        3. Template-Based Implementation of an STL String
        4. Summary
        5. Q&A
        6. Workshop
      3. Lesson 17. STL Dynamic Array Classes
        1. The Characteristics of std::vector
        2. Typical Vector Operations
        3. Understanding the Concepts of Size and Capacity
        4. The STL deque Class
        5. Summary
        6. Q&A
        7. Workshop
      4. Lesson 18. STL list and forward_list
        1. The Characteristics of a std::list
        2. Basic list Operations
        3. Reversing and Sorting Elements in a List
        4. Summary
        5. Q&A
        6. Workshop
      5. Lesson 19. STL Set Classes
        1. An Introduction to STL Set Classes
        2. Basic STL set and multiset Operations
        3. Pros and Cons of Using STL set and multiset
        4. Summary
        5. Q&A
        6. Workshop
      6. Lesson 20. STL Map Classes
        1. An Introduction to STL Map Classes
        2. Basic std::map and std::multimap Operations
        3. Supplying a Custom Sort Predicate
        4. Summary
        5. Q&A
        6. Workshop
    14. Part IV. More STL
      1. Lesson 21. Understanding Function Objects
        1. The Concept of Function Objects and Predicates
        2. Typical Applications of Function Objects
        3. Summary
        4. Q&A
        5. Workshop
      2. Lesson 22. C++11 Lambda Expressions
        1. What Is a Lambda Expression?
        2. How to Define a Lambda Expression
        3. Lambda Expression for a Unary Function
        4. Lambda Expression for a Unary Predicate
        5. Lambda Expression with State via Capture Lists [...]
        6. The Generic Syntax of Lambda Expressions
        7. Lambda Expression for a Binary Function
        8. Lambda Expression for a Binary Predicate
        9. Summary
        10. Q&A
        11. Workshop
      3. Lesson 23. STL Algorithms
        1. What Are STL Algorithms?
        2. Classification of STL Algorithms
        3. Usage of STL Algorithms
        4. Summary
        5. Q&A
        6. Workshop
      4. Lesson 24. Adaptive Containers: Stack and Queue
        1. The Behavioral Characteristics of Stacks and Queues
        2. Using the STL stack Class
        3. Using the STL queue Class
        4. Using the STL Priority Queue
        5. Summary
        6. Q&A
        7. Workshop
      5. Lesson 25. Working with Bit Flags Using STL
        1. The bitset Class
        2. Using std::bitset and Its Members
        3. The vector<bool>
        4. Summary
        5. Q&A
        6. Workshop
    15. Part V. Advanced C++ Concepts
      1. Lesson 26. Understanding Smart Pointers
        1. What Are Smart Pointers?
        2. How Are Smart Pointers Implemented?
        3. Types of Smart Pointers
        4. Popular Smart Pointer Libraries
        5. Summary
        6. Q&A
        7. Workshop
      2. Lesson 27. Using Streams for Input and Output
        1. Concept of Streams
        2. Important C++ Stream Classes and Objects
        3. Using std::cout for Writing Formatted Data to Console
        4. Using std::cin for Input
        5. Using std::fstream for File Handling
        6. Using std::stringstream for String Conversions
        7. Summary
        8. Q&A
        9. Workshop
      3. Lesson 28. Exception Handling
        1. What Is an Exception?
        2. What Causes Exceptions?
        3. Implementing Exception Safety via try and catch
        4. How Exception Handling Works
        5. Summary
        6. Q&A
        7. Workshop
      4. Lesson 29. Going Forward
        1. What’s Different in Today’s Processors?
        2. How to Better Use Multiple Cores
        3. Writing Great C++ Code
        4. Learning C++ Doesn’t Stop Here!
        5. Summary
        6. Q&A
        7. Workshop
    16. Appendixes
      1. Appendix A. Working with Numbers: Binary and Hexadecimal
        1. Decimal Numeral System
        2. Binary Numeral System
        3. Hexadecimal Numeral System
        4. Converting to a Different Base
      2. Appendix B. C++ Keywords
      3. Appendix C. Operator Precedence
      4. Appendix D. Answers
        1. Answers for Lesson 1
        2. Answers for Lesson 2
        3. Answers for Lesson 3
        4. Answers for Lesson 4
        5. Answers for Lesson 5
        6. Answers for Lesson 6
        7. Answers for Lesson 7
        8. Answers for Lesson 8
        9. Answers for Lesson 9
        10. Answers for Lesson 10
        11. Answers for Lesson 11
        12. Answers for Lesson 12
        13. Answers for Lesson 13
        14. Answers for Lesson 14
        15. Answers for Lesson 15
        16. Answers for Lesson 16
        17. Answers for Lesson 17
        18. Answers for Lesson 18
        19. Answers for Lesson 19
        20. Answers for Lesson 20
        21. Answers for Lesson 21
        22. Answers for Lesson 22
        23. Answers for Lesson 23
        24. Answers for Lesson 24
        25. Answers for Lesson 25
        26. Answers for Lesson 26
        27. Answers for Lesson 27
        28. Answers for Lesson 28
        29. Answers for Lesson 29
      5. Appendix E. ASCII Codes
        1. ASCII Table of Printable Characters
    17. Index