0%

In just one hour a day, you will have all the skills you need to begin programming in C++. With this complete tutorial, you will quickly master the basics, and then move on to more advanced features and concepts. Completely updated for the latest C++ standard, this book presents the language from a practical point of view, helping you learn how to use C++ to create faster, simpler, and more efficient C++ applications.

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

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

Learn best practices and avoid pitfalls

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

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

Learn on your own time, at your own pace:

  • No previous programming experience required

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

  • Learn object-oriented programming concepts such as encapsulation, abstraction, inheritance, and polymorphism

  • Use algorithms and containers from the Standard Template Library to write feature-rich yet stable C++ applications

  • Learn how automatic type deduction helps simplify C++ code

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

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

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

Table of Contents

  1. Cover Page
  2. Title Page
  3. Copyright Page
  4. Contents at a Glance
  5. Table of Contents
  6. Introduction
    1. Who Should Read This Book?
    2. Organization of This Book
    3. Conventions Used in This Book
    4. Sample Code for This Book
  7. About the Author
  8. Acknowledgments
  9. We Want to Hear from You!
  10. Reader Services
  11. Part I: The Basics
    1. Lesson 1. Getting Started
    2. A Brief History of C++
    3. Programming a C++ Application
    4. What’s New in C++20?
    5. Summary
    6. Q&A
    7. Workshop
    8. Lesson 2. The Anatomy of a C++ Program
    9. Parts of the Hello World Program
    10. Preprocessor Directive #include
    11. The Body of Your Program: main()
    12. The Concept of Namespaces
    13. Comments in C++ Code
    14. Functions in C++
    15. Basic Input Using std::cin and Output Using std::cout
    16. Summary
    17. Q&A
    18. Workshop
    19. Lesson 3. Using Variables, Declaring Constants
    20. What Is a Variable?
    21. Common Compiler-Supported C++ Variable Types
    22. Determining the Size of a Variable by Using sizeof()
    23. Automatic Type Inference Using auto
    24. Using typedef to Substitute a Variable’s Type
    25. What Is a Constant?
    26. Keywords You Cannot Use as Variable or Constant Names
    27. Summary
    28. Q&A
    29. Workshop
    30. Lesson 4. Managing Arrays and Strings
    31. What Is an Array?
    32. Multidimensional Arrays
    33. Dynamic Arrays
    34. C-Style Character Strings
    35. C++ Strings: Using std::string
    36. Summary
    37. Q&A
    38. Workshop
    39. Lesson 5. Working with Expressions, Statements, and Operators
    40. Statements
    41. Compound Statements, or Blocks
    42. Using Operators
    43. Summary
    44. Q&A
    45. Workshop
    46. Lesson 6. Controlling Program Flow
    47. Conditional Execution Using if...else
    48. Getting Code to Execute in Loops
    49. Modifying Loop Behavior Using continue and break
    50. Programming Nested Loops
    51. Summary
    52. Q&A
    53. Workshop
    54. Lesson 7. Organizing Code with Functions
    55. The Need for Functions
    56. Using Functions to Work with Different Forms of Data
    57. How Function Calls Are Handled by the Microprocessor
    58. Summary
    59. Q&A
    60. Workshop
    61. Lesson 8. Pointers and References Explained
    62. What Is a Pointer?
    63. Dynamic Memory Allocation
    64. Common Programming Mistakes When Using Pointers
    65. Pointer Programming Best Practices
    66. What Is a Reference?
    67. Summary
    68. Q&A
    69. Workshop
  12. Part II: Fundamentals of Object-Oriented C++ Programming
    1. Lesson 9. Classes and Objects
    2. The Concept of Classes and Objects
    3. The Keywords public and private
    4. Constructors
    5. Destructor
    6. The Copy Constructor
    7. Different Uses of Constructors and the Destructor
    8. The this Pointer
    9. Using sizeof() with a Class
    10. The Keyword struct and Its Differences from class
    11. Declaring a friend of a class
    12. Union: A Special Data Storage Mechanism
    13. Using Aggregate Initialization on Classes and structs
    14. Summary
    15. Q&A
    16. Workshop
    17. Lesson 10. Implementing Inheritance
    18. Basics of Inheritance
    19. Private Inheritance
    20. Protected Inheritance
    21. The Problem of Slicing
    22. Multiple Inheritance
    23. Avoiding Inheritance Using final
    24. Summary
    25. Q&A
    26. Workshop
    27. Lesson 11. Polymorphism
    28. Basics of Polymorphism
    29. Using Virtual Inheritance to Solve the Diamond Problem
    30. Using the Specifier override to Indicate the Intention to Override
    31. Using final to Prevent Function Overriding
    32. Virtual Copy Constructors?
    33. Summary
    34. Q&A
    35. Workshop
    36. Lesson 12. Operator Types and Operator Overloading
    37. What Are Operators in C++?
    38. Unary Operators
    39. Binary Operators
    40. The Function Operator (())
    41. The Move Constructor and Move Assignment Operator for High-Performance Programming
    42. User-Defined Literals
    43. Operators That Cannot Be Overloaded
    44. Summary
    45. Q&A
    46. Workshop
    47. Lesson 13. Casting Operators
    48. The Need for Casting
    49. Why C-Style Casts Are Not Popular with Some C++ Programmers
    50. The C++ Casting Operators
    51. Problems with the C++ Casting Operators
    52. Summary
    53. Q&A
    54. Workshop
    55. Lesson 14. An Introduction to Macros and Templates
    56. The Preprocessor and the Compiler
    57. Using the Macro #define to Define Constants
    58. Using #define to Write Macro Functions
    59. An Introduction to Templates
    60. Summary
    61. Q&A
    62. Workshop
  13. Part III: Learning the Standard Template Library (STL)
    1. Lesson 15. An Introduction to the Standard Template Library
    2. STL Containers
    3. STL Iterators
    4. STL Algorithms
    5. Interaction Between Containers and Algorithms Using Iterators
    6. Choosing the Right Container
    7. STL String Classes
    8. Summary
    9. Q&A
    10. Workshop
    11. Lesson 16. The STL String Class
    12. The Need for String Manipulation Classes
    13. Working with the STL String Class
    14. Template-Based Implementation of an STL String
    15. operator “"s in std::string
    16. Using std::string_view (Amended in C++20)
    17. Summary
    18. Q&A
    19. Workshop
    20. Lesson 17. STL Dynamic Array Classes
    21. The Characteristics of std::vector
    22. Typical Vector Operations
    23. Understanding the Concepts of Size and Capacity
    24. The STL deque Class
    25. Summary
    26. Q&A
    27. Workshop
    28. Lesson 18. STL list and forward_list
    29. The Characteristics of std::list
    30. Basic list Operations
    31. Reversing and Sorting Elements in a List
    32. Summary
    33. Q&A
    34. Workshop
    35. Lesson 19. STL set and multiset
    36. An Introduction to STL Set Classes
    37. Basic STL set and multiset Operations
    38. Pros and Cons of Using STL set and multiset
    39. Summary
    40. Q&A
    41. Workshop
    42. Lesson 20. STL map and multimap
    43. An Introduction to STL Map Classes
    44. Basic std::map and std::multimap Operations
    45. Supplying a Custom Sort Predicate
    46. STL’s Hash Table–Based Key/Value Container
    47. Summary
    48. Q&A
    49. Workshop
  14. Part IV: Lambda Expressions and STL Algorithms
    1. Lesson 21. Understanding Function Objects
    2. Function Objects and Predicates
    3. Typical Applications of Function Objects
    4. Summary
    5. Q&A
    6. Workshop
    7. Lesson 22. Lambda Expressions
    8. What Is a Lambda Expression?
    9. How to Define a Lambda Expression
    10. A Lambda Expression for a Unary Function
    11. A Lambda Expression for a Unary Predicate
    12. A Lambda Expression with State via Capture Lists ([...])
    13. A Lambda Expression for a Binary Function
    14. A Lambda Expression for a Binary Predicate
    15. Summary
    16. Q&A
    17. Workshop
    18. Lesson 23. STL Algorithms
    19. What Are STL Algorithms?
    20. Classification of STL Algorithms
    21. Usage of STL Algorithms
    22. C++20 Constrained Algorithms
    23. Summary
    24. Q&A
    25. Workshop
    26. Lesson 24. Adaptive Containers: Stack and Queue
    27. The Behavioral Characteristics of Stacks and Queues
    28. Using the STL stack Class
    29. Using the STL queue Class
    30. Using the STL Priority Queue
    31. Summary
    32. Q&A
    33. Workshop
    34. Lesson 25. Working with Bit Flags Using the STL
    35. The bitset Class
    36. Using std::bitset and Its Members
    37. The vector<bool> Class
    38. Summary
    39. Q&A
    40. Workshop
  15. Part V: Advanced C++ Concepts
    1. Lesson 26. Understanding Smart Pointers
    2. What Are Smart Pointers?
    3. How Are Smart Pointers Implemented?
    4. Types of Smart Pointers
    5. Popular Smart Pointer Libraries
    6. Summary
    7. Q&A
    8. Workshop
    9. Lesson 27. Using Streams for Input and Output
    10. The Concept of Streams
    11. Important C++ Stream Classes and Objects
    12. Using std::cout for Writing Formatted Data to the Console
    13. Using std::cin for Input
    14. Using std::fstream for File Handling
    15. Using std::stringstream for String Conversions
    16. Summary
    17. Q&A
    18. Workshop
    19. Lesson 28. Exception Handling
    20. What Is an Exception?
    21. What Causes Exceptions?
    22. Implementing Exception Safety via try and catch
    23. Throwing Exceptions of a Type by Using throw
    24. How Exception Handling Works
    25. Class std::exception
    26. A Custom Exception Class Derived from std::exception
    27. Summary
    28. Q&A
    29. Workshop
    30. Lesson 29. C++20 Concepts, Ranges, Views, and Adaptors
    31. Concepts
    32. The Ranges Library, Views, and Adaptors
    33. Summary
    34. Q&A
    35. Workshop
    36. Lesson 30. C++20 Threads
    37. Multithreading
    38. Summary
    39. Q&A
    40. Workshop
    41. Lesson 31. C++20 Modules and C++23
    42. Modules
    43. C++23 Expected Features
    44. Learning C++ Doesn’t Stop Here!
    45. Summary
    46. Q&A
    47. Workshop
  16. Part VI: Appendixes
    1. Appendix A. Working with Numbers: Binary and Hexadecimal
    2. Decimal Numeral System
    3. Binary Numeral System
    4. Hexadecimal Numeral System
    5. Converting to a Different Base
    6. Appendix B. C++ Keywords
    7. Appendix C. Writing Great C++ Code
    8. Appendix D. ASCII Codes
    9. ASCII Table of Printable Characters
    10. Appendix E. Answers
    11. Answers for Lesson 1
    12. Answers for Lesson 2
    13. Answers for Lesson 3
    14. Answers for Lesson 4
    15. Answers for Lesson 5
    16. Answers for Lesson 6
    17. Answers for Lesson 7
    18. Answers for Lesson 8
    19. Answers for Lesson 9
    20. Answers for Lesson 10
    21. Answers for Lesson 11
    22. Answers for Lesson 12
    23. Answers for Lesson 13
    24. Answers for Lesson 14
    25. Answers for Lesson 15
    26. Answers for Lesson 16
    27. Answers for Lesson 17
    28. Answers for Lesson 18
    29. Answers for Lesson 19
    30. Answers for Lesson 20
    31. Answers for Lesson 21
    32. Answers for Lesson 22
    33. Answers for Lesson 23
    34. Answers for Lesson 24
    35. Answers for Lesson 25
    36. Answers for Lesson 26
    37. Answers for Lesson 27
    38. Answers for Lesson 28
    39. Answers for Lesson 29
    40. Answers for Lesson 30
    41. Answers for Lesson 31
54.196.52.45