Table of Contents....5
About the Author....15
About the Technical Reviewer....16
Acknowledgments....17
About the Second Edition....18
Chapter 1: Introduction....19
Chapter 2: What Is C++?....20
C++ Standards....20
Chapter 3: C++ Compilers....21
Installing C++ Compilers....21
On Linux....21
On Windows....22
Chapter 4: Our First Program....23
Comments....23
Hello World Example....24
Chapter 5: Types....28
Fundamental Types....28
Boolean....28
Character Type....29
Integer Types....31
Floating-Point Types....33
Type void....33
Type Modifiers....34
Variable Declaration, Definition, and Initialization....34
Chapter 6: Exercises....36
Hello World and Comments....36
Declaration....36
Definition....37
Initialization....37
Chapter 7: Operators....39
Assignment Operator....39
Arithmetic Operators....39
Compound Assignment Operators....41
Increment/Decrement Operators....42
Chapter 8: Standard Input....43
Chapter 9: Exercises....45
Standard Input....45
Two Inputs....45
Multiple Inputs....46
Inputs and Arithmetic Operations....47
Postincrement and Compound Assignment....47
Integral and Floating-Point Division....48
Chapter 10: Arrays....49
Chapter 11: Pointers....51
Chapter 12: References....54
Chapter 13: Introduction to Strings....56
Defining a String....56
Concatenating Strings....57
Accessing Characters....58
Comparing Strings....59
String Input....60
A Pointer to a String....61
Substrings....61
Finding a Substring....62
Chapter 14: Automatic Type Deduction....64
Chapter 15: Exercises....66
Array Definition....66
Pointer to an Object....67
Reference Type....67
Strings....68
Strings from Standard Input....68
Creating a Substring....69
Finding a Single Character....70
Finding a Substring....71
Automatic Type Deduction....72
Chapter 16: Statements....73
Selection Statements....73
if Statement....73
Conditional Expression....75
The Logical Operators....77
Comparison Operators....79
switch Statement....82
Iteration Statements....83
for Statement....84
while Statement....85
do Statement....87
Chapter 17: Constants....88
Chapter 18: Exercises....90
A Simple if Statement....90
Logical Operators....91
The switch Statement....92
The for Loop....93
Array and the for Loop....94
The const Type Qualifier....94
Chapter 19: Functions....96
Introduction....96
Function Declaration....96
Function Definition....97
Return Statement....100
Passing Arguments....102
Passing by Value/Copy....102
Passing by Reference....103
Passing by Const Reference....104
Function Overloading....105
Chapter 20: Exercises....108
Function Definition....108
Separate Declaration and Definition....108
Function Parameters....109
Passing Arguments....110
Function Overloads....110
Chapter 21: Scope and Lifetime....112
Local Scope....112
Block Scope....112
Lifetime....113
Automatic Storage Duration....113
Dynamic Storage Duration....113
Static Storage Duration....114
Operators new and delete....114
Chapter 22: Exercises....116
Automatic Storage Duration....116
Dynamic Storage Duration....117
Automatic and Dynamic Storage Durations....118
Chapter 23: Classes – Introduction....120
Data Member Fields....120
Member Functions....121
Access Specifiers....123
Constructors....127
Default Constructor....127
Member Initialization....130
Copy Constructor....131
Copy Assignment....134
Move Constructor....135
Move Assignment....137
Operator Overloading....139
Destructors....145
Chapter 24: Exercises....148
Class Instance....148
Class with Data Members....148
Class with Member Function....149
Class with Data and Function Members....150
Class Access Specifiers....150
User-Defined Default Constructor and Destructor....151
Constructor Initializer List....152
User-Defined Copy Constructor....154
User-Defined Move Constructor....155
Overloading Arithmetic Operators....156
Chapter 25: Classes – Inheritance and Polymorphism....158
Inheritance....158
Polymorphism....162
Chapter 26: Exercises....167
Inheritance....167
Chapter 27: The static Specifier....171
Chapter 28: Templates....174
Function Templates....174
Class Templates....176
Template Specialization....180
Chapter 29: Enumerations....182
Chapter 30: Exercises....185
Static Variable....185
Static Data Member....186
Static Member Function....187
Function Template....188
Class Template....189
Scoped Enums....190
Enums in a switch....191
Chapter 31: Organizing Code....193
Header and Source Files....193
Header Guards....194
Namespaces....194
Chapter 32: Exercises....198
Header and Source Files....198
Multiple Source Files....199
Namespaces....200
Nested Namespaces....201
Chapter 33: Conversions....203
Implicit Conversions....203
Explicit Conversions....207
Chapter 34: Exceptions....211
Chapter 35: Smart Pointers....216
Unique Pointer....216
Shared Pointer....219
Chapter 36: Exercises....221
static_cast Conversion....221
A Simple Unique Pointer....222
Unique Pointer to an Object of a Class....222
Shared Pointer Exercise....223
Simple Polymorphism....224
Polymorphism II....225
Exception Handling....226
Multiple Exceptions....227
Chapter 37: Input/Output Streams....229
File Streams....229
String Streams....233
Chapter 38: C++ Standard Library and Friends....238
Containers....238
std::vector....239
std::array....241
std::set....242
std::map....244
std::pair....247
Other Containers....248
The Range-Based for Loop....248
Iterators....251
Algorithms and Utilities....254
std::sort....255
std::find....257
std::copy....258
Min and Max Elements....260
Lambda Expressions....261
Chapter 39: Exercises....269
Basic Vector....269
Deleting a Single Value....270
Deleting a Range of Elements....270
Finding Elements in a Vector....271
Basic Set....272
Set Data Manipulation....273
Set Member Functions....274
Search for Data in a Set....275
Basic Map....276
Inserting into a Map....277
Searching and Deleting from a Map....279
Lambda Expressions....280
Chapter 40: C++ Standards....283
C++11....283
Automatic Type Deduction....284
Range-Based Loops....284
Initializer Lists....285
Move Semantics....286
Lambda Expressions....286
The constexpr Specifier....287
Scoped Enumerators....288
Smart Pointers....288
std::unordered_set....290
std::unordered_map....292
std::tuple....294
static_assert....295
Introduction to Concurrency....296
Deleted and Defaulted Functions....303
Type Aliases....306
C++14....306
Binary Literals....307
Digit Separators....308
Auto for Functions....308
Generic Lambdas....309
std::make_unique....309
C++17....310
Nested Namespaces....310
Constexpr Lambdas....311
Structured Bindings....311
std::filesystem....313
std::string_view....317
std::any....319
std::variant....321
C++20....324
Modules....325
Concepts....327
Lambda Templates....331
[likely] and [unlikely] Attributes....332
Ranges....334
Coroutines....338
std::span....339
Mathematical Constants....340
C++23....341
Multidimensional Subscript Operator....342
Literal Suffixes for size_t....342
The #warning Preprocessor Directive....343
The std::string::contains() Member Function....343
std::print....345
Chapter 41: Projects....348
Project I: Book Inventory....348
Project II: Book Inventory – Multiple Files....363
Project III: Message Logger....368
Project IV: Message Logger – Multiple Files....387
Project V: Information System....393
Project VI: Information System – Multiple Files....423
Index....434
Learn the C++ programming language in a structured, straightforward, and friendly manner. This book teaches the basics of the modern C++ programming language, the C++ Standard Library, and modern C++ standards, including C++23. No previous programming experience is required.
C++ is a language like no other, surprising in its complexity, yet wonderfully sleek and elegant in so many ways. It is also a language that cannot be learned by guessing, one that is easy to get wrong and challenging to get right. To overcome this, each section is filled with real-world examples that gradually increase in complexity. Modern C++ for Absolute Beginners, Second Edition teaches more than just programming in C++23. It provides a solid C++ foundation to build upon.
The author takes you through the C++ programming language, the Standard Library, and C++11 to C++23 standard basics. Each chapter is accompanied by the right amount oftheory and plenty of source code examples. You will work with C++23 features and standards, yet you will also compare and take a look into previous versions of C++.
After reading this book, you'll be able to start programming in modern C++ standards. You will do so with plenty of relevant source code examples, freely available via a dedicated GitHub repository.
Beginner or novice programmers who wish to learn C++ programming. No prior programming experience is required.