SlideShare a Scribd company logo
C 20 for Programmers 3rd Edition P. Deitel pdf
download
https://ebookgate.com/product/c-20-for-programmers-3rd-edition-p-
deitel/
Get Instant Ebook Downloads – Browse at https://ebookgate.com
Get Your Digital Files Instantly: PDF, ePub, MOBI and More
Quick Digital Downloads: PDF, ePub, MOBI and Other Formats
JavaScript for Programmers 1st Edition Paul J. Deitel
https://ebookgate.com/product/javascript-for-programmers-1st-
edition-paul-j-deitel/
C for Java Programmers 1st Edition Harold Cabrera
https://ebookgate.com/product/c-for-java-programmers-1st-edition-
harold-cabrera/
C for Java Programmers 1st Edition Dario Laverde
https://ebookgate.com/product/c-for-java-programmers-1st-edition-
dario-laverde/
C How to Program 6th Edition Paul Deitel
https://ebookgate.com/product/c-how-to-program-6th-edition-paul-
deitel/
C How to Program 9e 9th Edition Paul Deitel
https://ebookgate.com/product/c-how-to-program-9e-9th-edition-
paul-deitel/
C How to Program 7th Edition Paul J. Deitel
https://ebookgate.com/product/c-how-to-program-7th-edition-paul-
j-deitel/
C How to Program Fourth Edition Harvey M. Deitel
https://ebookgate.com/product/c-how-to-program-fourth-edition-
harvey-m-deitel/
Internet World Wide Web How to Program Fourth Edition
P. J. Deitel
https://ebookgate.com/product/internet-world-wide-web-how-to-
program-fourth-edition-p-j-deitel/
Herding Cats A Primer for Programmers Who Lead
Programmers 1st Edition J. Hank Rainwater
https://ebookgate.com/product/herding-cats-a-primer-for-
programmers-who-lead-programmers-1st-edition-j-hank-rainwater/
C 20 for Programmers 3rd Edition P. Deitel
Deitel® Developer Series
C++ 20 for Programmers
Paul Deitel • Harvey Deitel
Many of the designations used by manufacturers and sellers to distinguish
their products are claimed as trademarks. Where those designations appear in
this book, and the publisher was aware of a trademark claim, the designations
have been printed with initial capital letters or in all capitals.
The authors and publisher have taken care in the preparation of this book, but
make no expressed or implied warranty of any kind and assume no
responsibility for errors or omissions. No liability is assumed for incidental or
consequential damages in connection with or arising out of the use of the
information or programs contained herein.
Copyright © 2021 Pearson Education, Inc.
All rights reserved. This publication is protected by copyright, and
permission must be obtained from the publisher prior to any prohibited
reproduction, storage in a retrieval system, or transmission in any form or by
any means, electronic, mechanical, photocopying, recording, or likewise. For
information regarding permissions, request forms and the appropriate
contacts within the Pearson Education Global Rights & Permissions
Department, please visit www.pearson.com/permissions.
ISBN-13: 978-0-13-690569-1
ISBN-10: 0-13-690569-1
Contents
Preface
Part 1: C++ Fundamentals Quickstart
Chapter 1. Introduction and Test-Driving a C++ Application
Chapter 2. Introduction to C++ Programming
Chapter 3. Control Statements, Part 1; Intro to C++20 Text
Formatting
Chapter 4. Control Statements, Part 2
Chapter 5. Functions
Part 2: Arrays, Pointers, Strings and Files
Chapter 6. arrays, vectors, C++20 Ranges and Functional-
Style Programming
Chapter 7. (Downplaying) Pointers in Modern C++
Chapter 8. strings, string_views, Text Files, CSV Files and
Regex
Part 3: Object-Oriented Programming
Chapter 9. Custom Classes
Chapter 10. OOP: Inheritance and Runtime Polymorphism
Chapter 11. Operator Overloading, Copy/Move Semantics and
Smart Pointers
Chapter 12. Exceptions and a Look Forward to Contracts
Part 4: Standard Library Containers, Iterators and Algorithms
Chapter 13. Standard Library Containers and Iterators
Chapter 14. Standard Library Algorithms and C++20 Ranges &
Views
Part 5: Advanced Topics
Chapter 15. Templates, C++20 Concepts and Metaprogramming
Chapter 16. C++20 Modules: Large-Scale Development
Chapter 17. Concurrent Programming; Intro to C++20
Coroutines
Part 6: Other Topics
Chapter 18. Stream I/O; C++20 Text Formatting: A Deeper
Look
Chapter 19. Other Topics; A Look Toward C++23 and Contracts
Part 7: Appendices
Appendix A: Operator Precedence and Grouping
Appendix B: Character Set
Appendix C: Fundamental Types
Appendix D: Number Systems
Appendix E: Preprocessor
Appendix F: Bits, Characters, C Strings and structs
Appendix G: C Legacy Code Topics
Appendix H: Using the Visual Studio Debugger
Appendix I: Using the GNU C++ Debugger
Appendix J: Using the Xcode Debugger
Table of Contents
Preface
Part 1: C++ Fundamentals Quickstart
Chapter 1. Introduction and Test-Driving a C++ Application
1.1 Introduction
1.2 Test-Driving a C++20 Application
Chapter 2. Introduction to C++ Programming
2.1 Introduction
2.2 First Program in C++: Displaying a Line of Text
2.3 Modifying Our First C++ Program
2.4 Another C++ Program: Adding Integers
2.5 Arithmetic
2.6 Decision Making: Equality and Relational Operators
2.7 Objects Natural: Creating and Using Objects of Standard
Library Class string
2.8 Wrap-Up
Chapter 3. Control Statements, Part 1; Intro to C++20 Text
Formatting
3.1 Introduction
3.2 Control Structures
3.3 if Single-Selection Statement
3.4 if…else Double-Selection Statement
3.5 while Iteration Statement
3.6 Counter-Controlled Iteration
3.7 Sentinel-Controlled Iteration
3.8 Nested Control Statements
3.9 Compound Assignment Operators
3.10 Increment and Decrement Operators
3.11 Fundamental Types Are Not Portable
3.12 Objects Natural Case Study: Arbitrary Sized Integers
3.13 C++20 Feature Mock-Up—Text Formatting with
Function format
3.14 Wrap-Up
Chapter 4. Control Statements, Part 2
4.1 Introduction
4.2 Essentials of Counter-Controlled Iteration
4.3 for Iteration Statement
4.4 Examples Using the for Statement
4.5 Application: Summing Even Integers
4.6 Application: Compound-Interest Calculations
4.7 do…while Iteration Statement
4.8 switch Multiple-Selection Statement
4.9 C++17: Selection Statements with Initializers
4.10 break and continue Statements
4.11 Logical Operators
4.12 Confusing the Equality (==) and Assignment (=)
Operators
4.13 C++20 Feature Mock-Up: [[likely]] and
[[unlikely]] Attributes
4.14 Objects Natural Case Study: Using the miniz-cpp
Library to Write and Read ZIP files
4.15 C++20 Feature Mock-Up: Text Formatting with Field
Widths and Precisions
4.16 Wrap-Up
Chapter 5. Functions
5.1 Introduction
5.2 Program Components in C++
5.3 Math Library Functions
5.4 Function Definitions and Function Prototypes
5.5 Order of Evaluation of a Function’s Arguments
5.6 Function-Prototype and Argument-Coercion Notes
5.7 C++ Standard Library Headers
5.8 Case Study: Random-Number Generation
5.9 Case Study: Game of Chance; Introducing Scoped enums
5.10 C++11’s More Secure Nondeterministic Random
Numbers
5.11 Scope Rules
5.12 Inline Functions
5.13 References and Reference Parameters
5.14 Default Arguments
5.15 Unary Scope Resolution Operator
5.16 Function Overloading
5.17 Function Templates
5.18 Recursion
5.19 Example Using Recursion: Fibonacci Series
5.20 Recursion vs. Iteration
5.21 C++17 and C++20: [[nodiscard]] Attribute
5.22 Lnfylun Lhqtomh Wjtz Qarcv: Qjwazkrplm xzz
Xndmwwqhlz
5.23 Wrap-Up
Part 2: Arrays, Pointers, Strings and Files
Chapter 6. arrays, vectors, C++20 Ranges and Functional-
Style Programming
6.1 Introduction
6.2 arrays
6.3 Declaring arrays
6.4 Initializing array Elements in a Loop
6.5 Initializing an array with an Initializer List
6.6 C++1 1 Range-Based for and C++20 Range-Based for
with Initializer
6.7 Setting array Elements with Calculations; Introducing
constexpr
6.8 Totaling array Elements
6.9 Using a Primitive Bar Chart to Display array Data
Graphically
6.10 Using array Elements as Counters
6.11 Using arrays to Summarize Survey Results
6.12 Sorting and Searching arrays
6.13 Multidimensional arrays
6.14 Intro to Functional-Style Programming
6.15 Objects Natural Case Study: C++ Standard Library Class
Template vector
6.16 Wrap-Up
Chapter 7. (Downplaying) Pointers in Modern C++
7.1 Introduction
7.2 Pointer Variable Declarations and Initialization
7.3 Pointer Operators
7.4 Pass-by-Reference with Pointers
7.5 Built-In Arrays
7.6 C++20: Using to_array to convert a Built-in Array to a
std::array
7.7 Using const with Pointers and the Data They Point To
7.8 sizeof Operator
7.9 Pointer Expressions and Pointer Arithmetic
7.10 Objects Natural Case Study: C++20 spans—Views of
Contiguous Container Elements
7.11 A Brief Intro to Pointer-Based Strings
7.12 Looking Ahead to Other Pointer Topics
7.13 Wrap-Up
Chapter 8. strings, string_views, Text Files, CSV Files and
Regex
8.1 Introduction
8.2 string Assignment and Concatenation
8.3 Comparing strings
8.4 Substrings
8.5 Swapping strings
8.6 string Characteristics
8.7 Finding Substrings and Characters in a string
8.8 Replacing Characters in a string
8.9 Inserting Characters into a string
8.10 C++11 Numeric Conversions
8.11 C++17 string_view
8.12 Files and Streams
8.13 Creating a Sequential File
8.14 Reading Data from a Sequential File
8.15 C++14 Reading and Writing Quoted Text
8.16 Updating Sequential Files
8.17 String Stream Processing
8.18 Raw String Literals
8.19 Objects Natural Case Study: Reading and Analyzing a
CSV File Containing Titanic Disaster Data
8.20 Objects Natural Case Study: Introduction to Regular
Expressions
8.21 Wrap-Up
Part 3: Object-Oriented Programming
Chapter 9. Custom Classes
9.1 Introduction
9.2 Test-Driving an Account Object
9.3 Account Class with a Data Member and Set and Get
Member Functions
9.4 Account Class: Custom Constructors
9.5 Software Engineering with Set and Get Member Functions
9.6 Account Class with a Balance
9.7 Time Class Case Study: Separating Interface from
Implementation
9.8 Compilation and Linking Process
9.9 Class Scope and Accessing Class Members
9.10 Access Functions and Utility Functions
9.11 Time Class Case Study: Constructors with Default
Arguments
9.12 Destructors
9.13 When Constructors and Destructors Are Called
9.14 Time Class Case Study: A Subtle Trap—Returning a
Reference or a Pointer to a private Data Member
9.15 Default Assignment Operator
9.16 const Objects and const Member Functions
9.17 Composition: Objects as Members of Classes
9.18 friend Functions and friend Classes
9.19 The this Pointer
9.20 static Class Members—Classwide Data and Member
Functions
9.21 Aggregates in C++20
9.22 Objects Natural Case Study: Serialization with JSON
9.23 Wrap-Up
Chapter 10. OOP: Inheritance and Runtime Polymorphism
10.1 Introduction
10.2 Base Classes and Derived Classes
10.3 Relationship between Base and Derived Classes
10.4 Constructors and Destructors in Derived Classes
10.5 Intro to Runtime Polymorphism: Polymorphic Video
Game
10.6 Relationships Among Objects in an Inheritance
Hierarchy
10.7 Virtual Functions and Virtual Destructors
10.8 Abstract Classes and Pure virtual Functions
10.9 Case Study: Payroll System Using Runtime
Polymorphism
10.10 Runtime Polymorphism, Virtual Functions and
Dynamic Binding “Under the Hood”
10.11 Non-Virtual Interface (NVI) Idiom
10.12 Program to an Interface, Not an Implementation
10.13 Runtime Polymorphism with std::variant and std::visit
10.14 Multiple Inheritance
10.15 protected Class Members
10.16 public, protected and private Inheritance
10.17 Wrap-Up
Chapter 11. Operator Overloading, Copy/Move Semantics and
Smart Pointers
11.1 Introduction
11.2 Using the Overloaded Operators of Standard Library
Class string
11.3 Operator Overloading Fundamentals
11.4 (Downplaying) Dynamic Memory Management with
new and delete
11.5 Modern C++ Dynamic Memory Management—RAII and
Smart Pointers
11.6 MyArray Case Study: Crafting a Valuable Class with
Operator Overloading
11.7 C++20 Three-Way Comparison Operator (<=>)
11.8 Converting Between Types
11.9 explicit Constructors and Conversion Operators
11.10 Overloading the Function Call Operator ()
11.11 Wrap-Up
Chapter 12. Exceptions and a Look Forward to Contracts
12.1 Introduction
12.2 Exception-Handling Flow of Control; Defining an
Exception Class
12.3 Exception Safety Guarantees and noexcept
12.4 Rethrowing an Exception
12.5 Stack Unwinding and Uncaught Exceptions
12.6 When to Use Exception Handling
12.7 Constructors, Destructors and Exception Handling
12.8 Processing new Failures
12.9 Standard Library Exception Hierarchy
12.10 C++’s Alternative to the finally Block
12.11 Libraries Often Support Both Exceptions and Error
Codes
12.12 Logging
12.13 Looking Ahead to Contracts
12.14 Wrap-Up
Part 4: Standard Library Containers, Iterators and Algorithms
Chapter 13. Standard Library Containers and Iterators
13.1 Introduction
13.2 Introduction to Containers
13.3 Working with Iterators
13.4 A Brief Introduction to Algorithms
13.5 Sequence Containers
13.6 vector Sequence Container
13.7 list Sequence Container
13.8 deque Sequence Container
13.9 Associative Containers
13.10 Container Adaptors
13.11 bitset Near Container
13.12 Optional: A Brief Intro to Big O
13.13 Optional: A Brief Intro to Hash Tables
13.14 Wrap-Up
Chapter 14. Standard Library Algorithms and C++20 Ranges &
Views
14.1 Introduction
14.2 Algorithm Requirements: C++20 Concepts
14.3 Lambdas and Algorithms
14.4 Algorithms
14.5 Function Objects (Functors)
14.6 Projections
14.7 C++20 Views and Functional-Style Programming
14.8 Intro to Parallel Algorithms
14.9 Standard Library Algorithm Summary
14.10 A Look Ahead to C++23 Ranges
14.11 Wrap-Up
Part 5: Advanced Topics
Chapter 15. Templates, C++20 Concepts and Metaprogramming
15.1 Introduction
15.2 Custom Class Templates and Compile-Time
Polymorphism
15.3 C++20 Function Template Enhancements
15.4 C++20 Concepts: A First Look
15.5 Type Traits
15.6 C++20 Concepts: A Deeper Look
15.7 Testing C++20 Concepts with static_assert
15.8 Creating a Custom Algorithm
15.9 Creating a Custom Container and Iterators
15.10 Default Arguments for Template Type Parameters
15.11 Variable Templates
15.12 Variadic Templates and Fold Expressions
15.13 Template Metaprogramming
15.14 Wrap-Up
Chapter 16. C++20 Modules: Large-Scale Development
16.1 Introduction
16.2 Compilation and Linking Prior to C++20
16.3 Advantages and Goals of Modules
16.4 Example: Transitioning to Modules—Header Units
16.5 Example: Creating and Using a Module
16.6 Global Module Fragment
16.7 Separating Interface from Implementation
16.8 Partitions
16.9 Additional Modules Examples
16.10 Modules Can Reduce Translation Unit Sizes and
Compilation Times
16.11 Migrating Code to Modules
16.12 Future of Modules and Modules Tooling
16.13 Wrap-Up
Chapter 17. Concurrent Programming; Intro to C++20
Coroutines
Part 6: Other Topics
Chapter 18. Stream I/O; C++20 Text Formatting: A Deeper Look
Chapter 19. Other Topics; A Look Toward C++23 and Contracts
Part 7: Appendices
Appendix A: Operator Precedence and Grouping
Appendix B: Character Set
Appendix C: Fundamental Types
Appendix D: Number Systems
Appendix E: Preprocessor
Appendix F: Bits, Characters, C Strings and structs
Appendix G: C Legacy Code Topics
Appendix H: Using the Visual Studio Debugger
Appendix I: Using the GNU C++ Debugger
Appendix J: Using the Xcode Debugger
Preface
Welcome to the C++ programming language and C++20 for Programmers.
This book presents leading-edge computing technologies for software
developers.
These are exciting times in the programming-languages community with each
of the major languages striving to keep pace with compelling new
programming technologies. The ISO C++ Standards Committee now releases
a new standard every three years and the compiler vendors implement the
new features promptly. C++20 for Programmers is based on the new C++20
standard.
Live-Code Approach
At the heart of the book is the Deitel signature live-code approach. We
present most concepts in the context of complete working programs followed
by one or more sample executions. Read the Before You Begin section that
follows this Preface to learn how to set up your Windows, macOS or Linux
computer to run the hundreds of code examples. All the source code is
available at
https://www.deitel.com/c-plus-plus-20-for-programmers
We recommend that you compile and run each program as you study it.
“Rough-Cut” E-Book for O’Reilly Online Learning
Subscribers
You are viewing an early-access “rough cut” of C++20 for Programmers.
We prepared this content carefully, but it has not yet been reviewed or
copy edited and is subject to change. As we complete each chapter, we’ll
post it here. Please send any corrections, comments, questions and
suggestions for improvement to paul@deitel.com and I’ll respond
promptly. Check here frequently for updates.
“Sneak Peek” Videos for O’Reilly Online Learning Subscribers
As an O’Reilly Online Learning subscriber, you also have access to the
“sneak peek” of our new C++20 Fundamentals LiveLessons videos at:
https://learning.oreilly.com/videos/c-20-fundamentals-part
Co-author Paul Deitel immediately records each video lesson as we complete
each rough-cut e-book chapter. Lessons go live on O’Reilly Online Learning
a few days later. Again, check here frequently for updates.
Modern C++
20 The C++ programming language is popular for developing systems
software, embedded systems, operating systems, real-time systems, computer
games, communications systems and other high-performance computer
applications. C++20 for Programmers is an introductory-through-
intermediate-level, professional tutorial presentation of C++. The book is not
a full-language reference manual, nor is it a “cookbook.” We focus on
Modern C++, which consists of the four most recent C++ standards—C++11,
C++14, C++17 and C++20. Throughout the book, features from these
standards are marked with icons in the margins like the 20 icon shown here.
Compilers
We tested every program in the book on three popular free compilers:
• Visual C++ in Microsoft Visual Studio Community edition on Windows,
• Clang in Xcode on macOS, and
• GNU C++ on Linux and in the GNU Compiler Collection (GCC) Docker
container.
At the time of this writing, some C++20 features are fully implemented in all
three compilers, some are implemented in a subset of the three and some are
not implemented at all. We point out these issues as appropriate and will
update our online content as the compiler vendors implement the rest of
C++20’s features. C++20 compiler support for many more compilers is
tracked at
https://en.cppreference.com/w/cpp/compiler_support
We’ll also post updates on the book’s website at
https://deitel.com/books/c-plus-plus-20-for-programmers
Target Audiences
C++20 for Programmers and our C++20 Fundamentals LiveLessons videos
have several target audiences:
• Non-C++ software developers who are about to do a C++ project and
want to learn the latest version of the language, C++20, in the context of
a professional-style, language tutorial.
• Software developers who may have learned C++ in college or used it
professionally some time ago and want to refresh their C++ knowledge in
the context of C++20.
• C++ software developers who want to learn C++20 in the context of a
professional-style, language tutorial.
PERF Security Focus on Performance and Security
Issues
Throughout the book, we call your attention to performance and security
issues with the icons you see here in the margin.
“Objects Natural” Learning Approach
In your C++ programs, you’ll create and use many objects of carefully-
developed-and-tested preexisting classes that enable you to perform
significant tasks with minimal code. These classes typically come from:
• the C++ Standard Library,
• platform-specific libraries, such as those provided by Microsoft
Windows, Apple macOS or various Linux versions,
• free third-party C++ libraries, often created by the open-source
community, and
• libraries created by fellow developers, such as those in your organization.
To help you appreciate this style of programming, early in the book you’ll
create and use objects of preexisting classes before creating your own custom
classes in later chapters. We call this the “objects natural” approach.
Our “Objects Natural” Learning Approach evolved organically as we worked
on our Python for Programmers book
(https://learning.oreilly.com/library/view/python-
for-programmers/9780135231364/) and our Python Fundamentals
LiveLessons videos
(https://learning.oreilly.com/videos/python-
fundamentals/9780135917411), but C++20 for Programmers is the
first book in which we’re using the term, “Objects Natural.”
“Rough-Cut” Table of Contents (Subject to Change)
Part 1: C++ Fundamentals Quickstart
1. Introduction and Test-Driving a C++ Application
2. Introduction to C++ Programming
3. Control Statements, Part 1; Intro to C++20 Text Formatting
4. Control Statements, Part 2
5. Functions
Part 2: Arrays, Pointers, Strings and Files
6. array, vectors, C++20 Ranges and Functional-Style Programming
7. (Downplaying) Pointers in Modern C++
8. string, Regular Expressions and Files
Part 3: Object-Oriented Programming
9. Classes
10. Inheritance and Polymorphism
11. Operator Overloading
12. Exceptions: A Deeper Look
Part 4: Standard Library Containers, Iterators and Algorithms
13. Standard Library Containers and Iterators
14. Standard Library Algorithms; Functional Programming: A Deeper Look
Part 5: Advanced Topics
15. C++20 Modules
16. Intro to Custom Templates and C++20 Concepts
17. Concurrent Programming; Intro to C++20 Coroutines
Part 6: Other Topics
18. Stream I/O; C++20 Text Formatting: A Deeper Look
19. Other Topics; A Look Toward C++23 and Contracts
Part 7: Appendices
A. Operator Precedence and Grouping
B. Character Set
C. Fundamental Types
D. Number Systems
E. Preprocessor
F. Bits, Characters, C Strings and structs
G. C Legacy Code Topics
H. Using the Visual Studio Debugger
I. Using the GNU C++ Debugger
J. Using the Xcode Debugger
Contacting the Authors
As you read the book, if you have questions, we’re easy to reach at
deitel@deitel.com
or
https://deitel.com/contact-us
We’ll respond promptly. For book updates, visit
https://deitel.com/c-plus-plus-20-for-programmers
Join the Deitel & Associates, Inc. Social Media Communities
Join the Deitel social media communities on
• Facebook®—https://facebook.com/DeitelFan
• LinkedIn®—https://bit.ly/DeitelLinkedIn
• Twitter®—https://twitter.com/deitel
• YouTube®—https://youtube.com/DeitelTV
About the Authors
Paul J. Deitel, CEO and Chief Technical Officer of Deitel & Associates,
Inc., is an MIT graduate with 39 years of experience in computing. Paul is
one of the world’s most experienced programming-languages trainers, having
taught professional courses to software developers since 1992. He has
delivered hundreds of programming courses to academic, industry,
government and military clients internationally, including Pearson Education
through O’Reilly Online Learning, Cisco, IBM, Siemens, Sun Microsystems
(now Oracle), Dell, Fidelity, NASA at the Kennedy Space Center, the
National Severe Storm Laboratory, White Sands Missile Range, Rogue Wave
Software, Boeing, Nortel Networks, Puma, iRobot, UCLA and many more.
He and his co-author, Dr. Harvey M. Deitel, are the world’s best-selling
programming-language textbook/professional book/video/webinar authors.
Dr. Harvey M. Deitel, Chairman and Chief Strategy Officer of Deitel &
Associates, Inc., has 59 years of experience in computing. Dr. Deitel earned
B.S. and M.S. degrees in Electrical Engineering from MIT and a Ph.D. in
Mathematics from Boston University— he studied computing in each of
these programs before they spun off Computer Science. He has extensive
college teaching experience, including earning tenure and serving as the
Chairman of the Computer Science Department at Boston College before
founding Deitel & Associates, Inc., in 1991 with his son, Paul. The Deitels’
publications have earned international recognition, with more than 100
translations published in Japanese, German, Russian, Spanish, French, Polish,
Italian, Simplified Chinese, Traditional Chinese, Korean, Portuguese, Greek,
Urdu and Turkish. Dr. Deitel has delivered hundreds of programming courses
to academic, corporate, government and military clients.
About Deitel® & Associates, Inc.
Deitel & Associates, Inc., founded by Paul Deitel and Harvey Deitel, is an
internationally recognized authoring and corporate training organization,
specializing in computer programming languages, object technology, mobile
app development and Internet-and-web software technology. The company’s
training clients include some of the world’s largest companies, government
agencies, branches of the military, and academic institutions. The company
offers instructor-led training courses delivered at client sites worldwide on
major programming languages.
Through its 45-year publishing partnership with Pearson/Prentice Hall, Deitel
& Associates, Inc., publishes leading-edge programming textbooks and
professional books in print and e-book formats, LiveLessons video courses,
O’Reilly Online Learning live webinars and Revel™ interactive
multimedia courses.
To learn more about Deitel on-site corporate training, visit
https://deitel.com/training
To request a proposal for on-site, instructor-led training worldwide, write to:
deitel@deitel.com
Individuals wishing to purchase Deitel books can do so at
https://www.amazon.com
Bulk orders by corporations, the government, the military and academic
institutions should be placed directly with Pearson. For more information,
visit
https://www.informit.com/store/sales.aspx
Part 1: C++ Fundamentals Quickstart
Chapter 1. Introduction and Test-Driving a
C++ Application
C 20 for Programmers 3rd Edition P. Deitel
Objectives
In this chapter, you’ll do one or more of the following:
■ Test-drive a C++20 application in the Visual C++ compiler in
Microsoft Visual Studio Community edition on Windows.
■ Test-drive a C++20 application in the Clang compiler in Xcode on
macOS.
■ Test-drive a C++20 application in the GNU C++ compiler on Linux.
■ Test-drive a C++20 application in the GNU Compiler Collection
(GCC) Docker Container in Docker running natively over Windows
10, macOS and/or Linux.
1.1 Introduction
1.2 Test-Driving a C++20 Application
1.2.1 Compiling and Running a C++20 Application with Visual
Studio 2019 Community Edition on Windows 10
1.2.2 Compiling and Running a C++20 Application with Xcode
on macOS
1.2.3 Compiling and Running a C++20 Application with GNU
C++ on Linux
1.2.4 Compiling and Running a C++20 Application with GNU
C++ in the GCC Docker Container in Docker Running
Natively Over Windows 10, macOS and/or Linux
1.1 Introduction
Welcome to C++—one of the world’s most widely used, high-performance,
computer-programming languages—and its current version C++20.
If you’re reading this, you’re on the O’Reilly Online Learning platform
(formerly called Safari) viewing an early-access Rough Cut of our
forthcoming book C++20 for Programmers, scheduled for publication this
summer. We have prepared this content carefully, but it has not yet been
peer reviewed or copy edited and is subject to change. When we complete
this chapter, we’ll post the reviewed and copy edited version here.
Please send any corrections, comments, questions and suggestions for
improvement to paul@deitel.com and I’ll respond promptly. Check for
updates here and on the book’s web page:
https://deitel.com/c-plus-plus-20-for-programmers
This book is written for developers using one or more of the following
popular desktop platforms—Microsoft Windows 10, macOS and Linux. We
tested every program on three popular free compilers:
• Visual C++ in Microsoft Visual Studio Community edition on Windows
10,
• Clang in Xcode on macOS, and
• GNU C++ on Linux and in the GNU Compiler Collection (GCC) Docker
container.1
1. At Deitel, we use current, powerful multicore Apple Mac computers that enable us to run macOS
natively, and Windows 10 and Linux through virtual machines in VMWare Fusion. Docker runs
natively on Windows, macOS and Linux systems.
This early-access version of Chapter 1 contains test-drives demonstrating
how to compile and run a C++20 application using these compilers and
platforms. The published version of this chapter will contain additional
introductory material.
At the time of this writing, some C++20 features are fully implemented in all
three compilers, some are implemented in a subset of the three and some are
not implemented at all. We point out these issues as appropriate and will
update our online content as the compiler vendors implement the rest of
C++20’s features. C++20 compiler support for many more compilers is
tracked at:
https://en.cppreference.com/w/cpp/compiler_support
“Sneak Peek” Videos for O’Reilly Online Learning Subscribers
As an O’Reilly Online Learning subscriber, you also have access to the
“sneak peek” of our new C++20 Fundamentals LiveLessons videos at:
https://learning.oreilly.com/videos/c-20-fundamentals-part
Co-author Paul Deitel immediately records each video lesson as we complete
the corresponding chapter. Lessons go live on O’Reilly Online Learning a
few days later. Again, check here frequently for updates.
1.2 Test-Driving a C++20 Application
In this section, you’ll compile, run and interact with your first C++
application—a guess-the-number game, which picks a random number from
1 to 1000 and prompts you to guess it. If you guess correctly, the game ends.
If you guess incorrectly, the application indicates whether your guess is
higher or lower than the correct number. There’s no limit on the number of
guesses you can make.
Usually, this application randomly selects the correct answer as you execute
the program. We’ve disabled that aspect of the application so that it uses the
same correct answer every time the program executes (though this may vary
by compiler). So, you can use the same guesses we use and see the same
results.
Summary of the Test-Drives
We’ll demonstrate running a C++ application using:
• Microsoft Visual Studio 2019 Community edition for Windows (Section
1.2.1)
• Clang in Xcode on macOS (Section 1.2.2).
• GNU C++ in a shell on Linux (Section 1.2.3)
• GNU C++ in a shell running inside the GNU Compiler Collection (GCC)
Docker container. This requires Docker to be installed and running.
You need to read only the section that corresponds to your platform. At the
time of this writing, GNU C++ supports the most C++20 features of the three
compilers we use.
1.2.1 Compiling and Running a C++20 Application with Visual
Studio 2019 Community Edition on Windows 10
In this section, you’ll run a C++ program on Windows using Microsoft
Visual Studio 2019 Community edition. There are several versions of Visual
Studio available—on some versions, the options, menus and instructions we
present might differ slightly. From this point forward, we'll simply say
“Visual Studio” or “the IDE.”
Step 1: Checking Your Setup
If you have not already done so, read the Before You Begin section of this
book for instructions on installing the IDE and downloading the book’s code
examples.
Step 2: Launching Visual Studio
Open Visual Studio from the Start menu. The IDE displays the following
Visual Studio 2019 window containing:
Close this window for now by clicking the X in its tab—you can access this
window any time by selecting File > Start Window. We use the > character
to indicate selecting a menu item from a menu. For example, the notation File
> Open indicates that you should select the Open menu item from the File
menu.
Step 3: Creating a Project
A project is a group of related files, such as the C++ source-code files that
compose an application. Visual Studio organizes applications into projects
and solutions, which contain one or more projects. Multiple-project solutions
are used to create large-scale applications. Each application in this book
requires only a single-project solution.
To work our code examples, you’ll begin with an Empty Project and add
files to it. To create a project:
1. Select File > New > Project… to display the Create a New Project
dialog:
2. In the preceding dialog, select the Empty Project template with the
tags C++, Windows and Console. This template is for programs that
execute at the command line in a Command Prompt window.
Depending on the version of Visual Studio you’re using and the options
you have installed, there may be many other project templates installed.
You can narrow down your choices using the Search for templates
textbox and the drop-down lists below it. Click Next to display the
Configure your new project dialog:
3. Provide a Project name and Location for your project. For the Project
name, we specified cpp20_test. For the Location, we selected the
examples folder containing this book’s code examples. Click Create
to open your new project in Visual Studio.
At this point, the Visual Studio creates your project, places its folder in
C:UsersYourUserAccountDocumentsexamples
(or the folder you specified) and opens the main window:
This window displays editors as tabbed windows (one for each file) when
you’re editing code. On the left side is the Solution Explorer for viewing
and managing your application’s files. In this book’s examples, you’ll
typically place each program’s code files in the Source Files folder. If the
Solution Explorer is not displayed, you can display it by selecting View >
Solution Explorer.
Step 4: Adding the GuessNumber.cpp File into the Project
Next, you’ll add GuessNumber.cpp to the project you created in Step 3.
In the Solution Explorer:
1. Right-click the Source Files folder and select Add > Existing Item….
2. In the dialog that appears, navigate to the ch01 subfolder of the book’s
examples folder, GuessNumber.cpp and click Add.2
2. For the multiple source-code-file programs that you’ll see in later chapters, select all the files for a
given program. When you begin creating programs yourself, you can right click the Source Files
folder and select Add > New Item… to display a dialog for adding a new file.
Step 5: Configuring Your Project to Use C++20
The Visual C++ compiler in Visual Studio supports several versions of the
C++ standard. For this book, we use C++20, which we must configure in our
project’s settings:
1. Right-click the project’s node— —in the Solution Explorer and
select Properties to display the project’s cpp20_test Property Pages
dialog:
2. In the left column, expand the C/C++ node, then select Language.
3. In the right column, click in the field to the right of C++ Language
Standard, click the down arrow, then select Preview - Features from
the Latest C++ Working Draft (/std:c++latest) and click OK. In a
future version of Visual Studio, Microsoft will change this option to
ISO C++20 Standard (/std:c++20).
Step 6: Compiling and Running the Project
To compile and run the project so you can test-drive the application, select
Debug > Start without debugging or type Ctrl + F5. If the program
compiles correctly, Visual Studio opens a Command Prompt window and
executes the program. We changed the Command Prompt’s color scheme and
font size for readability:
Step 7: Entering Your First Guess
At the ? prompt, type 500 and press Enter. The application displays "Too
high. Try again." to indicate the value you entered is greater than the
number the application chose as the correct guess:
Step 8: Entering Another Guess
At the next prompt, type 250 and press Enter. The application displays
"Too high. Try again.", because the value you entered once again is
greater than the correct guess:
Step 9: Entering Additional Guesses
Continue to play the game by entering values until you guess the correct
number. When you guess correctly, the application displays "Excellent!
You guessed the number!":
Step 10: Playing the Game Again or Exiting the Application
After you guess the correct number, the application asks if you’d like to play
another game. At the "Would you like to play again (y or
n)?" prompt, entering y causes the application to choose a new number and
start a new game. Entering n terminates the application. Each time you
execute this application from the beginning (Step 6), it will choose the same
numbers for you to guess.
Reusing This Project for Subsequent Examples
You can follow the steps in this section to create a separate project for every
application in the book. However, for our examples, you may find it more
convenient to remove the current program from the project then add a new
one. To remove a file from your project (but not your system), select it in the
Solution Explorer then press Del (or Delete). You can then repeat Step 4 to
add a different program to the project.
1.2.2 Compiling and Running a C++20 Application with Xcode
on macOS
In this section, you’ll run a C++ program on a macOS using the Clang
compiler in Apple’s Xcode IDE.
Step 1: Checking Your Setup
If you have not already done so, read the Before You Begin section of this
book for instructions on installing the IDE and downloading the book’s code
examples.
Step 2: Launching Xcode
Open a Finder window, select Applications and double-click the Xcode icon
( ). If this is your first time running Xcode, the Welcome to Xcode
window appears:
Close this window by clicking the X in the upper left corner—you can access
it any time by selecting Window > Welcome to Xcode. We use the >
character to indicate selecting a menu item from a menu. For example, the
notation File > Open… indicates that you should select the Open… menu
item from the File menu.
Step 3: Creating a Project
A project is a group of related files, such as the C++ source-code files that
compose an application. The Xcode projects we created for this book’s
examples are Command Line Tool projects that you’ll execute directly in
the IDE. To create a project:
1. Select File > New > Project….
2. At the top of the Choose a template for your new project dialog,
click macOS.
3. Under Application, click Command Line Tool and click Next.
4. For Product Name, enter a name for your project—we specified
cpp20_test.
5. In the Language drop-down list, select C++ then click Next.
6. Specify where you want to save your project. We selected the
examples folder containing this book’s code examples.
7. Click Create.
Xcode creates your project and displays the workspace window initially
showing three areas—the Navigator area, Editor area and Utilities area:
The left-side Navigator area has icons at its top for the navigators that can be
displayed there. For this book, you’ll primarily work with
• Project ( )—Shows all the files and folders in your project.
• Issue ( )—Shows you warnings and errors generated by the compiler.
Clicking a navigator button displays the corresponding navigator panel.
The middle Editor area is for managing project settings and editing source
code. This area is always displayed in your workspace window. Selecting a
file in the Project navigator, the file’s contents display in the Editor area.
You will not use the right-side Utilities area in this book. There’s also a
Debug area in which you’ll run and interact with the guess-the-number
program. This will appear below the Editor area.
The workspace window’s toolbar contains options for executing a program:
displaying the progress of tasks executing in Xcode:
and hiding or showing the left (Navigator), right (Utilities) and bottom
(Debug) areas:
Step 4: Configuring the Project to Compile Using C++20
The Clang compiler in Xcode supports several versions of the C++ standard.
For this book, we use C++20, which we must configure in our project’s
settings:
1. In the Project navigator, select your project’s name (cpp20_test).
2. In the Editors area’s left side, select your project’s name under
TARGET.
3. At the top of the Editors area, click Build Settings, and just below it,
click All.
4. Scroll to the Apple Clang - Language - C++ section.
5. Click the value to the right of C++ Language Dialect and select
Other….
6. In the popup area, replace the current setting with c++2a and press
Enter. In a future version of Xcode, Apple will provide a C++20 option
for C++ Language Dialect.
Step 5: Deleting the main.cpp File from the Project
By default, Xcode creates a main.cpp source-code file containing a simple
program that displays "Hello, World!". You won’t use main.cpp in
this test-drive, so you should delete the file. In the Project navigator, right-
click the main.cpp file and select Delete. In the dialog that appears, select
Move to Trash. The file will not be removed from your system until you
empty your trash.
Step 6: Adding the GuessNumber.cpp File into the Project
In a Finder window, open the ch01 folder in the book’s examples folder,
then drag GuessNumber.cpp onto the Guess Number folder in the
Project navigator. In the dialog that appears, ensure that Copy items if
needed is checked, then click Finish.3
3. For the multiple source-code-file programs that you’ll see later in the book, drag all the files for a
given program to the project’s folder. When you begin creating your own programs, you can right
click the project’s folder and select New File… to display a dialog for adding a new file.
Step 7: Compiling and Running the Project
To compile and run the project so you can test-drive the application, simply
click the run ( ) button on Xcode’s toolbar. If the program compiles
correctly, Xcode opens the Debug area and executes the program in the right
half of the Debug area:
The application displays "Please type your first guess.", then
displays a question mark (?) as a prompt on the next line.
Step 8: Entering Your First Guess
Click in the Debug area, then type 500 and press Return
The application displays "Too low. Try again.", meaning that the
value you entered is less than the number the application chose as the correct
guess.
Step 9: Entering Another Guess
At the next prompt, enter 750:
The application displays "Too low. Try again.", because the value
you entered once again is less than the correct guess.
Step 10: Entering Additional Guesses
Continue to play the game by entering values until you guess the correct
number. When you guess correctly, the application displays "Excellent!
You guessed the number.":
Playing the Game Again or Exiting the Application
After you guess the correct number, the application asks if you’d like to play
another game. At the "Would you like to play again (y or
n)?" prompt, entering y causes the application to choose a new number and
start a new game. Entering n terminates the application. Each time you
execute this application from the beginning (Step 7), it will choose the same
numbers for you to guess.
Reusing This Project for Subsequent Examples
You can follow the steps in this section to create a separate project for every
application in the book. However, for our examples, you may find it more
convenient to remove the current program from the project then add a new
one. To remove a file from your project (but not your system), right-click the
file in the Project navigator and select Delete. In the dialog that appears,
select Move to Trash. You can then repeat Step 6 to add a different program
to the project.
1.2.3 Compiling and Running a C++20 Application with GNU
C++ on Linux
For this test drive, we assume that you read the Before You Begin section and
that you placed the downloaded examples in your user account’s
Documents folder.
Step 1: Changing to the ch01 Folder
From a Linux shell, use the cd command to change to the ch01 subfolder of
the book’s examples folder:
Click here to view code image
~$ cd ~/Documents/examples/ch01
~/Documents/examples/ch01$
In this section’s figures, we use bold to highlight the text that you type. The
prompt in our Ubuntu Linux shell uses a tilde (~) to represent the home
directory. Each prompt ends with the dollar sign ($). The prompt may differ
on your Linux system.
Step 2: Compiling the Application
Before running the application, you must first compile it:
Click here to view code image
~/Documents/examples/ch01$ g++ -std=c++2a GuessNumber.cpp -
~/Documents/examples/ch01$
The g++ command compiles the application:
• The -std=c++2a option indicates that we’re using C++20—c++2a
will become c++20 in a future GNU C++ release.
• The -o option names the executable file (GuessNumber) that you’ll
use to run the program.
Step 3: Running the Application
Type ./GuessNumber at the prompt and press Enter to run the program:
Click here to view code image
~/Documents/examples/ch01$ ./GuessNumber
I have a number between 1 and 1000.
Can you guess my number?
Please type your first guess.
?
The ./ tells Linux to run a file from the current directory and is required to
indicate that GuessNumber is an executable file.
Step 4: Entering Your First Guess
The application displays "Please type your first guess.", then
displays a question mark (?) as a prompt on the next line. At the prompt,
enter 500—note that the outputs may vary based on the compiler you’re
using:
Click here to view code image
~/Documents/examples/ch01$ ./GuessNumber
I have a number between 1 and 1000.
Can you guess my number?
Please type your first guess.
? 500
Too high. Try again.
?
The application displays "Too high. Try again.", meaning that the
value you entered is greater than the number the application chose as the
correct guess.
Step 5: Entering Another Guess
At the next prompt, enter 250:
Click here to view code image
~/Documents/examples/ch01$ ./GuessNumber
I have a number between 1 and 1000.
Can you guess my number?
Please type your first guess.
? 500
Too high. Try again.
? 250
Too low. Try again.
?
This time the application displays "Too low. Try again.", because
the value you entered is less than the correct guess.
Step 6: Entering Additional Guesses
Continue to play the game by entering values until you guess the correct
number. When you guess correctly, the application displays "Excellent!
You guessed the number.":
Click here to view code image
Too low. Try again.
? 375
Too low. Try again.
? 437
Too high. Try again.
? 406
Too high. Try again.
? 391
Too high. Try again.
? 383
Too low. Try again.
? 387
Too high. Try again.
? 385
Too high. Try again.
? 384
Excellent! You guessed the number.
Would you like to play again (y or n)?
Step 7: Playing the Game Again or Exiting the Application
After you guess the correct number, the application asks if you’d like to play
another game. At the "Would you like to play again (y or
n)?" prompt, entering y causes the application to choose a new number and
start a new game. Entering n terminates the application and returns you to the
shell. Each time you execute this application from the beginning (Step 3), it
will choose the same numbers for you to guess.
1.2.4 Compiling and Running a C++20 Application with GNU
C++ in the GCC Docker Container in Docker Running
Natively Over Windows 10, macOS and/or Linux
At the time of this writing, GNU C++ implements the most C++20 features.
For this reason, you may want to use the latest GNU C++ compiler on your
system. One of the most convenient cross-platform ways to do this is by
using the GNU Compiler Collection (GCC) Docker container. This section
assumes you’ve already installed Docker Desktop (Windows or macOS) or
Docker Engine (Linux).
Executing the GNU Compiler Collection (GCC) Docker Container
Open a Command Prompt (Windows), Terminal (macOS/Linux) or shell
(Linux), then perform the following steps to launch the GCC Docker
Container:
1. Use the cd command to navigate to the examples folder containing
this book’s examples.
Discovering Diverse Content Through
Random Scribd Documents
Fig. 34—Showing how to force glass blowpipe (A) into
vitreous (B). (Page 80.)
Fig. 35—Showing bulging out of vitreous
caused by blowing air through glass blowpipe.
(Page 80.)
Fig. 36—Showing the vitreous (A) removed.
Holding the eye suspended by its optic nerve, force the glass
blowpipe through the vitreous until it all but touches the posterior
part of the retina (Fig. 34); blow gently at first, increasing the
pressure until the vitreous suddenly bulges outward. (Fig. 35.) If the
iris has been cut away close to the ora serrata, the vitreous will not
only bulge forward, but it will fall out. If, however, it does not detach
itself at once, insert the scalpel close to the choroid and with its flat
side press downward until a separation occurs. Do not let the
vitreous drop out too suddenly, because it may tear the retina. Let
the vitreous detach itself slowly by the force of its own weight,
though it will be well to hold some of its weight on the scalpel. (Fig.
36.)
Fig. 37—A. Showing retina folded upon itself by blowing air at it through
the glass blowpipe. (Page 83.)
Fig. 38—A. Showing folded retina suspended from its attachment, so sclerotic
and choroid may be easily cut away. (Page 83.)
After the vitreous has been removed, turn the eye upward, and by
blowing strongly through the blowpipe at the marginal edge of the
retina, turn the retina upon itself. Repeat this until the retina lies in a
small wrinkled lump at the “bottom” of the posterior part of the eye.
(Fig. 37.) Invert the eye (Fig. 38) and cut away both the choroid and
the sclerotic close to the optic nerve. No care need be taken in doing
this until the scissors come close to the optic nerve. (Fig. 39.)
Fig. 39—Showing the sclerotic nearly all cut away.
Fig. 40—Isolated retina, with optic nerve attached.
After the choroid and the sclerotic have been cut away, drop the
retina into some water, and it will slowly unfold itself by “ballooning”
out into a perfect and beautiful specimen. (Fig. 40.) But, if it is
desired to study the specimen closely, it is better to suspend it in a
jar or bottle made of thin glass, and containing a 5 per cent. solution
of formaldehyde. Remember that the retina is a delicate membrane
in any state; the slightest rough handling may cause it to be torn, or
otherwise damaged. If the vessel, in which the specimen has been
placed and suspended, has enough preserving fluid to completely fill
it, and it is firmly stoppered, the whole thing may be inverted, and
turned in any direction, even abruptly, without fear of damaging the
retina. This way of keeping the retina will give opportunity to inspect
and study the inside as well as the outside of the membrane; the
blood-vessels, and other important parts easily recognized.
C 20 for Programmers 3rd Edition P. Deitel
THE SAGITTAL OR VERTICAL SECTION OF THE EYE
Place an eye in a 5 per cent. solution of formaldehyde for about
two weeks. If the eye is kept in that solution longer than that time,
the lens is apt to become so hard that in cutting it the capsule and
suspensory ligament will be torn, and the lens will then become
detached; if for a shorter space of time, the lens and other tissues
will be so soft that all may be so badly torn or lacerated, that a
perfect specimen will not be possible.
It sometimes happens that in keeping a number of eyes together
in a vessel for the purpose of hardening them in the formaldehyde
solution, the corneas of some will be crushed in. For this dissection,
select an eye that has the cornea in perfect condition.
Remove all the outside tissues with the scissors, being particular
to have the region immediately surrounding the optic nerve perfectly
clear and clean. If the optic nerve is longer than 5 mm., cut it off to
that length.
Fig. 41—Showing the beginning of the cutting of the eye for
sagittal sections.
Fig. 42—Showing method of cutting through the crystalline lens.
To cut the eye in two, use a safety-razor blade; never a scalpel.
The latter is too thick, too dull, and too clumsy a tool. Begin by
cutting through the optic nerve; dividing it as nearly as possible into
halves. (Fig. 41.) Continue cutting through the sclerotic and all
underlying tissues, stopping at the corneo-scleral junction, but do
not, during this procedure, even touch the lens. After the eye has
been thus partly separated into, as nearly as possible, two equal
parts, lay it down upon the cornea, and, holding the razor blade in
the forefingers and thumbs of both hands, cut the lens in two by
forcing the blade down through it. (Fig. 42.) Partly open the cut eye
to allow one jaw of the large scissors to enter, turn the eye over so
the cornea will rest on that jaw, and then cut through the cornea.
(Fig. 43.)
Fig. 43—Showing method of cutting through the cornea and completing the two
sagittal sections.
The two specimens may be kept indefinitely by placing them in a 3
per cent. formaldehyde solution. It will be well to remove the lens
from one of the specimens, because it will give better opportunity to
see the anatomical relationships. Also, these specimens should be
mounted, one above the other, between two pieces of glass, before
placing them in the receptacle that is to hold them.
Much can be studied in such specimens. Moreover, they present to
view the various parts of the organ of vision in such an impressive
way, that one does not soon forget the wonderful appearance of the
construction of this, Nature’s perfect camera. (Fig. 44.)
Fig. 44—Sagittal section enlarged.
If another eye is cut into two parts, additional interesting
specimens may be procured; for instance, one showing the presence
of the second coat only, the retina having been torn out. Another
good specimen may be made by removing all of the inner tissues,
and leaving only the sclerotic and cornea. This specimen will show
that the first coat is almost entirely a coat which affords strength
and protection to the parts that lie within.
C 20 for Programmers 3rd Edition P. Deitel
THE PAPILLA, PUNCTA LACRIMALIA, AND NASAL
DUCT
The only way to dissect the lacrimal apparatus, other ocular
accessories, and the extrinsic muscles, is to procure the head of
some animal, preferably a calf’s head, because of its size. Any
butcher will supply one for from forty to sixty cents. Have the lower
jaw removed. It will make a less bulky piece of material to handle.
Close to the inner canthus, on the inner side of each lid, will be
found a little rounded eminence—lacrimal papilla—in the centre of
which is a small opening—punctum lacrimalis. Both may be seen
better on the lower lid, if it is pulled down, and on the upper lid, if it
is pulled up.
Fig. 45—Showing only a part of a calf’s head and the knitting-needles inserted in
the puncta. (Page 94.)
Fig. 46.
Be supplied with two knitting-needles. Take one, lubricate its full
length with a little vaseline, lard, oil, or any other lubricant. Insert
the needle into the punctum of the lower lid, and push it downward
and forward, aiming to come out in the nose a short distance from
its end. At first it may be a little difficult to get the needle started; if
so, just wiggle the needle, pushing it at the same time as directed,
until the nasal duct is found. Do not remove the needle. To insert
the other needle into the punctum of the upper lid is rather difficult;
for that reason the punctum of the lower lid was chosen, first.
Grease the needle, as was done to the first one, and, with a little
patience and careful manipulation, the canal opening and its course
will soon be found. The needle may then be pushed through until it
meets the first one. (Fig. 45.) From the puncta lacrimalia to the
place of meeting of the two needles, marks the course of the two
canaliculi and their junction before they merge and form the nasal
duct. Leave the needles where they are, and begin cutting away the
skin. The needles will then mark the course of each canal and the
duct very plainly. With the small scissors the canals and the duct
may be loosened from the surrounding tissues. Or, the scalpel may
be used to lay open the canals, cutting along over the top of the
needles. (Fig. 46.)
The cilia, palpebræ, palpebral conjunctiva, ocular conjunctiva, and
other superficial ocular accessories may be examined without
dissection.
MEIBOMIAN GLANDS AND DUCTS
An examination of the eyelids will show the openings of the ducts
of the meibomian glands a short distance back of the cilia. Very fine
pins or needles that have been greased may be easily inserted for a
short distance into the ducts, and then a dissection made along the
course of the duct as outlined by the presence of the inserted pins
or needles. Another way to see the glands is to slice through the
ducts, with the scalpel or safety-razor blade, the entire width of
either eyelid. This will separate the glands into two parts and show
their length, breadth and structure.
ENUCLEATION OF THE ORBITAL CONTENTS
The eyes one procures from a butcher or a slaughter house will
always have the extrinsic tissues so badly cut and torn that
identification of the various parts and their relations is impossible.
Therefore, it is best to supply one’s self with the head of an animal,
such as a sheep or a calf, and dissect an eye with all its extrinsic
tissues intact. For this dissection, a hammer and a chisel are
necessary in addition to the tools needed for doing the previous
dissections.
Fig. 47—Showing method of making the initial cuts in the skin. (Page 97.)
Fig. 48—Part of calf’s head, showing the first cut to be made in the bones of the
orbit. (Page 102.)
Welcome to Our Bookstore - The Ultimate Destination for Book Lovers
Are you passionate about books and eager to explore new worlds of
knowledge? At our website, we offer a vast collection of books that
cater to every interest and age group. From classic literature to
specialized publications, self-help books, and children’s stories, we
have it all! Each book is a gateway to new adventures, helping you
expand your knowledge and nourish your soul
Experience Convenient and Enjoyable Book Shopping Our website is more
than just an online bookstore—it’s a bridge connecting readers to the
timeless values of culture and wisdom. With a sleek and user-friendly
interface and a smart search system, you can find your favorite books
quickly and easily. Enjoy special promotions, fast home delivery, and
a seamless shopping experience that saves you time and enhances your
love for reading.
Let us accompany you on the journey of exploring knowledge and
personal growth!
ebookgate.com

More Related Content

PDF
C 20 for Programmers 3rd Edition P. Deitel
PDF
C 20 for Programmers 3rd Edition P. Deitel
PDF
Get C 20 for Programmers 3rd Edition P. Deitel free all chapters
PDF
C 20 for Programmers 3rd Edition P. Deitel
PDF
C 20 for Programmers 3rd Edition Harvey Deitel
PDF
C++ How to Program 10th Edition Deitel Solutions Manual
PDF
(eBook PDF) C++ How to Program 10th Edition by Paul J. Deitel
PDF
(eBook PDF) C++ How to Program 10th Edition by Paul J. Deitel
C 20 for Programmers 3rd Edition P. Deitel
C 20 for Programmers 3rd Edition P. Deitel
Get C 20 for Programmers 3rd Edition P. Deitel free all chapters
C 20 for Programmers 3rd Edition P. Deitel
C 20 for Programmers 3rd Edition Harvey Deitel
C++ How to Program 10th Edition Deitel Solutions Manual
(eBook PDF) C++ How to Program 10th Edition by Paul J. Deitel
(eBook PDF) C++ How to Program 10th Edition by Paul J. Deitel

Similar to C 20 for Programmers 3rd Edition P. Deitel (20)

PDF
Starting Out With C Early Objects 7th Edition 7th Edition Tony Gaddis
PDF
Programming c++
PDF
(eBook PDF) Starting Out with C++: From Control Structures through Objects 8t...
PDF
(eBook PDF) Starting Out with C++: From Control Structures through Objects, B...
PDF
C++ How to Program 10th Edition Deitel Solutions Manual
PDF
Starting Out with C++: Early Objects 9th Edition by Tony Gaddis (eBook PDF)
PPT
programming week 2.ppt
PDF
Starting Out with C++: Early Objects 9th Edition by Tony Gaddis (eBook PDF)
PDF
Starting Out with C++: Early Objects 9th Edition by Tony Gaddis (eBook PDF)
PDF
Starting Out with C++: Early Objects 9th Edition by Tony Gaddis (eBook PDF)
PDF
Object Oriented Programming With C Sharma A K
PDF
Download full ebook of Programming in C 2nd Edition Safari instant download pdf
PDF
Starting out with C from control structures through objects Eighth Edition To...
PDF
(eBook PDF) Starting Out with C++: From Control Structures through Objects 8t...
PDF
(eBook PDF) Starting Out with C++: From Control Structures through Objects 8t...
PDF
Starting Out with C++: Early Objects 9th Edition by Tony Gaddis (eBook PDF)
PDF
Programming in C 2nd Edition Safari download pdf
PDF
Starting Out with C++: Early Objects 9th Edition by Tony Gaddis (eBook PDF)
PDF
Introduction to c++
PDF
(eBook PDF) Starting Out with C++: Early Objects 9th Edition
Starting Out With C Early Objects 7th Edition 7th Edition Tony Gaddis
Programming c++
(eBook PDF) Starting Out with C++: From Control Structures through Objects 8t...
(eBook PDF) Starting Out with C++: From Control Structures through Objects, B...
C++ How to Program 10th Edition Deitel Solutions Manual
Starting Out with C++: Early Objects 9th Edition by Tony Gaddis (eBook PDF)
programming week 2.ppt
Starting Out with C++: Early Objects 9th Edition by Tony Gaddis (eBook PDF)
Starting Out with C++: Early Objects 9th Edition by Tony Gaddis (eBook PDF)
Starting Out with C++: Early Objects 9th Edition by Tony Gaddis (eBook PDF)
Object Oriented Programming With C Sharma A K
Download full ebook of Programming in C 2nd Edition Safari instant download pdf
Starting out with C from control structures through objects Eighth Edition To...
(eBook PDF) Starting Out with C++: From Control Structures through Objects 8t...
(eBook PDF) Starting Out with C++: From Control Structures through Objects 8t...
Starting Out with C++: Early Objects 9th Edition by Tony Gaddis (eBook PDF)
Programming in C 2nd Edition Safari download pdf
Starting Out with C++: Early Objects 9th Edition by Tony Gaddis (eBook PDF)
Introduction to c++
(eBook PDF) Starting Out with C++: Early Objects 9th Edition
Ad

Recently uploaded (20)

PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
Lesson notes of climatology university.
PDF
Classroom Observation Tools for Teachers
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPTX
GDM (1) (1).pptx small presentation for students
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
Institutional Correction lecture only . . .
PPTX
master seminar digital applications in india
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
Cell Structure & Organelles in detailed.
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
Cell Types and Its function , kingdom of life
PDF
Pre independence Education in Inndia.pdf
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
human mycosis Human fungal infections are called human mycosis..pptx
Microbial diseases, their pathogenesis and prophylaxis
STATICS OF THE RIGID BODIES Hibbelers.pdf
Lesson notes of climatology university.
Classroom Observation Tools for Teachers
Anesthesia in Laparoscopic Surgery in India
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
GDM (1) (1).pptx small presentation for students
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Institutional Correction lecture only . . .
master seminar digital applications in india
Pharmacology of Heart Failure /Pharmacotherapy of CHF
O7-L3 Supply Chain Operations - ICLT Program
Abdominal Access Techniques with Prof. Dr. R K Mishra
Cell Structure & Organelles in detailed.
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Cell Types and Its function , kingdom of life
Pre independence Education in Inndia.pdf
Module 4: Burden of Disease Tutorial Slides S2 2025
Ad

C 20 for Programmers 3rd Edition P. Deitel

  • 1. C 20 for Programmers 3rd Edition P. Deitel pdf download https://ebookgate.com/product/c-20-for-programmers-3rd-edition-p- deitel/ Get Instant Ebook Downloads – Browse at https://ebookgate.com
  • 2. Get Your Digital Files Instantly: PDF, ePub, MOBI and More Quick Digital Downloads: PDF, ePub, MOBI and Other Formats JavaScript for Programmers 1st Edition Paul J. Deitel https://ebookgate.com/product/javascript-for-programmers-1st- edition-paul-j-deitel/ C for Java Programmers 1st Edition Harold Cabrera https://ebookgate.com/product/c-for-java-programmers-1st-edition- harold-cabrera/ C for Java Programmers 1st Edition Dario Laverde https://ebookgate.com/product/c-for-java-programmers-1st-edition- dario-laverde/ C How to Program 6th Edition Paul Deitel https://ebookgate.com/product/c-how-to-program-6th-edition-paul- deitel/
  • 3. C How to Program 9e 9th Edition Paul Deitel https://ebookgate.com/product/c-how-to-program-9e-9th-edition- paul-deitel/ C How to Program 7th Edition Paul J. Deitel https://ebookgate.com/product/c-how-to-program-7th-edition-paul- j-deitel/ C How to Program Fourth Edition Harvey M. Deitel https://ebookgate.com/product/c-how-to-program-fourth-edition- harvey-m-deitel/ Internet World Wide Web How to Program Fourth Edition P. J. Deitel https://ebookgate.com/product/internet-world-wide-web-how-to- program-fourth-edition-p-j-deitel/ Herding Cats A Primer for Programmers Who Lead Programmers 1st Edition J. Hank Rainwater https://ebookgate.com/product/herding-cats-a-primer-for- programmers-who-lead-programmers-1st-edition-j-hank-rainwater/
  • 5. Deitel® Developer Series C++ 20 for Programmers Paul Deitel • Harvey Deitel
  • 6. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and the publisher was aware of a trademark claim, the designations have been printed with initial capital letters or in all capitals. The authors and publisher have taken care in the preparation of this book, but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for incidental or consequential damages in connection with or arising out of the use of the information or programs contained herein. Copyright © 2021 Pearson Education, Inc. All rights reserved. This publication is protected by copyright, and permission must be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permissions, request forms and the appropriate contacts within the Pearson Education Global Rights & Permissions Department, please visit www.pearson.com/permissions. ISBN-13: 978-0-13-690569-1 ISBN-10: 0-13-690569-1
  • 7. Contents Preface Part 1: C++ Fundamentals Quickstart Chapter 1. Introduction and Test-Driving a C++ Application Chapter 2. Introduction to C++ Programming Chapter 3. Control Statements, Part 1; Intro to C++20 Text Formatting Chapter 4. Control Statements, Part 2 Chapter 5. Functions Part 2: Arrays, Pointers, Strings and Files Chapter 6. arrays, vectors, C++20 Ranges and Functional- Style Programming Chapter 7. (Downplaying) Pointers in Modern C++ Chapter 8. strings, string_views, Text Files, CSV Files and Regex Part 3: Object-Oriented Programming Chapter 9. Custom Classes Chapter 10. OOP: Inheritance and Runtime Polymorphism Chapter 11. Operator Overloading, Copy/Move Semantics and Smart Pointers Chapter 12. Exceptions and a Look Forward to Contracts Part 4: Standard Library Containers, Iterators and Algorithms Chapter 13. Standard Library Containers and Iterators Chapter 14. Standard Library Algorithms and C++20 Ranges & Views Part 5: Advanced Topics Chapter 15. Templates, C++20 Concepts and Metaprogramming Chapter 16. C++20 Modules: Large-Scale Development
  • 8. Chapter 17. Concurrent Programming; Intro to C++20 Coroutines Part 6: Other Topics Chapter 18. Stream I/O; C++20 Text Formatting: A Deeper Look Chapter 19. Other Topics; A Look Toward C++23 and Contracts Part 7: Appendices Appendix A: Operator Precedence and Grouping Appendix B: Character Set Appendix C: Fundamental Types Appendix D: Number Systems Appendix E: Preprocessor Appendix F: Bits, Characters, C Strings and structs Appendix G: C Legacy Code Topics Appendix H: Using the Visual Studio Debugger Appendix I: Using the GNU C++ Debugger Appendix J: Using the Xcode Debugger
  • 9. Table of Contents Preface Part 1: C++ Fundamentals Quickstart Chapter 1. Introduction and Test-Driving a C++ Application 1.1 Introduction 1.2 Test-Driving a C++20 Application Chapter 2. Introduction to C++ Programming 2.1 Introduction 2.2 First Program in C++: Displaying a Line of Text 2.3 Modifying Our First C++ Program 2.4 Another C++ Program: Adding Integers 2.5 Arithmetic 2.6 Decision Making: Equality and Relational Operators 2.7 Objects Natural: Creating and Using Objects of Standard Library Class string 2.8 Wrap-Up Chapter 3. Control Statements, Part 1; Intro to C++20 Text Formatting 3.1 Introduction 3.2 Control Structures 3.3 if Single-Selection Statement 3.4 if…else Double-Selection Statement 3.5 while Iteration Statement 3.6 Counter-Controlled Iteration 3.7 Sentinel-Controlled Iteration 3.8 Nested Control Statements 3.9 Compound Assignment Operators 3.10 Increment and Decrement Operators
  • 10. 3.11 Fundamental Types Are Not Portable 3.12 Objects Natural Case Study: Arbitrary Sized Integers 3.13 C++20 Feature Mock-Up—Text Formatting with Function format 3.14 Wrap-Up Chapter 4. Control Statements, Part 2 4.1 Introduction 4.2 Essentials of Counter-Controlled Iteration 4.3 for Iteration Statement 4.4 Examples Using the for Statement 4.5 Application: Summing Even Integers 4.6 Application: Compound-Interest Calculations 4.7 do…while Iteration Statement 4.8 switch Multiple-Selection Statement 4.9 C++17: Selection Statements with Initializers 4.10 break and continue Statements 4.11 Logical Operators 4.12 Confusing the Equality (==) and Assignment (=) Operators 4.13 C++20 Feature Mock-Up: [[likely]] and [[unlikely]] Attributes 4.14 Objects Natural Case Study: Using the miniz-cpp Library to Write and Read ZIP files 4.15 C++20 Feature Mock-Up: Text Formatting with Field Widths and Precisions 4.16 Wrap-Up Chapter 5. Functions 5.1 Introduction 5.2 Program Components in C++ 5.3 Math Library Functions 5.4 Function Definitions and Function Prototypes 5.5 Order of Evaluation of a Function’s Arguments 5.6 Function-Prototype and Argument-Coercion Notes
  • 11. 5.7 C++ Standard Library Headers 5.8 Case Study: Random-Number Generation 5.9 Case Study: Game of Chance; Introducing Scoped enums 5.10 C++11’s More Secure Nondeterministic Random Numbers 5.11 Scope Rules 5.12 Inline Functions 5.13 References and Reference Parameters 5.14 Default Arguments 5.15 Unary Scope Resolution Operator 5.16 Function Overloading 5.17 Function Templates 5.18 Recursion 5.19 Example Using Recursion: Fibonacci Series 5.20 Recursion vs. Iteration 5.21 C++17 and C++20: [[nodiscard]] Attribute 5.22 Lnfylun Lhqtomh Wjtz Qarcv: Qjwazkrplm xzz Xndmwwqhlz 5.23 Wrap-Up Part 2: Arrays, Pointers, Strings and Files Chapter 6. arrays, vectors, C++20 Ranges and Functional- Style Programming 6.1 Introduction 6.2 arrays 6.3 Declaring arrays 6.4 Initializing array Elements in a Loop 6.5 Initializing an array with an Initializer List 6.6 C++1 1 Range-Based for and C++20 Range-Based for with Initializer 6.7 Setting array Elements with Calculations; Introducing constexpr 6.8 Totaling array Elements 6.9 Using a Primitive Bar Chart to Display array Data
  • 12. Graphically 6.10 Using array Elements as Counters 6.11 Using arrays to Summarize Survey Results 6.12 Sorting and Searching arrays 6.13 Multidimensional arrays 6.14 Intro to Functional-Style Programming 6.15 Objects Natural Case Study: C++ Standard Library Class Template vector 6.16 Wrap-Up Chapter 7. (Downplaying) Pointers in Modern C++ 7.1 Introduction 7.2 Pointer Variable Declarations and Initialization 7.3 Pointer Operators 7.4 Pass-by-Reference with Pointers 7.5 Built-In Arrays 7.6 C++20: Using to_array to convert a Built-in Array to a std::array 7.7 Using const with Pointers and the Data They Point To 7.8 sizeof Operator 7.9 Pointer Expressions and Pointer Arithmetic 7.10 Objects Natural Case Study: C++20 spans—Views of Contiguous Container Elements 7.11 A Brief Intro to Pointer-Based Strings 7.12 Looking Ahead to Other Pointer Topics 7.13 Wrap-Up Chapter 8. strings, string_views, Text Files, CSV Files and Regex 8.1 Introduction 8.2 string Assignment and Concatenation 8.3 Comparing strings 8.4 Substrings 8.5 Swapping strings 8.6 string Characteristics
  • 13. 8.7 Finding Substrings and Characters in a string 8.8 Replacing Characters in a string 8.9 Inserting Characters into a string 8.10 C++11 Numeric Conversions 8.11 C++17 string_view 8.12 Files and Streams 8.13 Creating a Sequential File 8.14 Reading Data from a Sequential File 8.15 C++14 Reading and Writing Quoted Text 8.16 Updating Sequential Files 8.17 String Stream Processing 8.18 Raw String Literals 8.19 Objects Natural Case Study: Reading and Analyzing a CSV File Containing Titanic Disaster Data 8.20 Objects Natural Case Study: Introduction to Regular Expressions 8.21 Wrap-Up Part 3: Object-Oriented Programming Chapter 9. Custom Classes 9.1 Introduction 9.2 Test-Driving an Account Object 9.3 Account Class with a Data Member and Set and Get Member Functions 9.4 Account Class: Custom Constructors 9.5 Software Engineering with Set and Get Member Functions 9.6 Account Class with a Balance 9.7 Time Class Case Study: Separating Interface from Implementation 9.8 Compilation and Linking Process 9.9 Class Scope and Accessing Class Members 9.10 Access Functions and Utility Functions 9.11 Time Class Case Study: Constructors with Default Arguments
  • 14. 9.12 Destructors 9.13 When Constructors and Destructors Are Called 9.14 Time Class Case Study: A Subtle Trap—Returning a Reference or a Pointer to a private Data Member 9.15 Default Assignment Operator 9.16 const Objects and const Member Functions 9.17 Composition: Objects as Members of Classes 9.18 friend Functions and friend Classes 9.19 The this Pointer 9.20 static Class Members—Classwide Data and Member Functions 9.21 Aggregates in C++20 9.22 Objects Natural Case Study: Serialization with JSON 9.23 Wrap-Up Chapter 10. OOP: Inheritance and Runtime Polymorphism 10.1 Introduction 10.2 Base Classes and Derived Classes 10.3 Relationship between Base and Derived Classes 10.4 Constructors and Destructors in Derived Classes 10.5 Intro to Runtime Polymorphism: Polymorphic Video Game 10.6 Relationships Among Objects in an Inheritance Hierarchy 10.7 Virtual Functions and Virtual Destructors 10.8 Abstract Classes and Pure virtual Functions 10.9 Case Study: Payroll System Using Runtime Polymorphism 10.10 Runtime Polymorphism, Virtual Functions and Dynamic Binding “Under the Hood” 10.11 Non-Virtual Interface (NVI) Idiom 10.12 Program to an Interface, Not an Implementation 10.13 Runtime Polymorphism with std::variant and std::visit 10.14 Multiple Inheritance 10.15 protected Class Members
  • 15. 10.16 public, protected and private Inheritance 10.17 Wrap-Up Chapter 11. Operator Overloading, Copy/Move Semantics and Smart Pointers 11.1 Introduction 11.2 Using the Overloaded Operators of Standard Library Class string 11.3 Operator Overloading Fundamentals 11.4 (Downplaying) Dynamic Memory Management with new and delete 11.5 Modern C++ Dynamic Memory Management—RAII and Smart Pointers 11.6 MyArray Case Study: Crafting a Valuable Class with Operator Overloading 11.7 C++20 Three-Way Comparison Operator (<=>) 11.8 Converting Between Types 11.9 explicit Constructors and Conversion Operators 11.10 Overloading the Function Call Operator () 11.11 Wrap-Up Chapter 12. Exceptions and a Look Forward to Contracts 12.1 Introduction 12.2 Exception-Handling Flow of Control; Defining an Exception Class 12.3 Exception Safety Guarantees and noexcept 12.4 Rethrowing an Exception 12.5 Stack Unwinding and Uncaught Exceptions 12.6 When to Use Exception Handling 12.7 Constructors, Destructors and Exception Handling 12.8 Processing new Failures 12.9 Standard Library Exception Hierarchy 12.10 C++’s Alternative to the finally Block 12.11 Libraries Often Support Both Exceptions and Error Codes
  • 16. 12.12 Logging 12.13 Looking Ahead to Contracts 12.14 Wrap-Up Part 4: Standard Library Containers, Iterators and Algorithms Chapter 13. Standard Library Containers and Iterators 13.1 Introduction 13.2 Introduction to Containers 13.3 Working with Iterators 13.4 A Brief Introduction to Algorithms 13.5 Sequence Containers 13.6 vector Sequence Container 13.7 list Sequence Container 13.8 deque Sequence Container 13.9 Associative Containers 13.10 Container Adaptors 13.11 bitset Near Container 13.12 Optional: A Brief Intro to Big O 13.13 Optional: A Brief Intro to Hash Tables 13.14 Wrap-Up Chapter 14. Standard Library Algorithms and C++20 Ranges & Views 14.1 Introduction 14.2 Algorithm Requirements: C++20 Concepts 14.3 Lambdas and Algorithms 14.4 Algorithms 14.5 Function Objects (Functors) 14.6 Projections 14.7 C++20 Views and Functional-Style Programming 14.8 Intro to Parallel Algorithms 14.9 Standard Library Algorithm Summary 14.10 A Look Ahead to C++23 Ranges 14.11 Wrap-Up
  • 17. Part 5: Advanced Topics Chapter 15. Templates, C++20 Concepts and Metaprogramming 15.1 Introduction 15.2 Custom Class Templates and Compile-Time Polymorphism 15.3 C++20 Function Template Enhancements 15.4 C++20 Concepts: A First Look 15.5 Type Traits 15.6 C++20 Concepts: A Deeper Look 15.7 Testing C++20 Concepts with static_assert 15.8 Creating a Custom Algorithm 15.9 Creating a Custom Container and Iterators 15.10 Default Arguments for Template Type Parameters 15.11 Variable Templates 15.12 Variadic Templates and Fold Expressions 15.13 Template Metaprogramming 15.14 Wrap-Up Chapter 16. C++20 Modules: Large-Scale Development 16.1 Introduction 16.2 Compilation and Linking Prior to C++20 16.3 Advantages and Goals of Modules 16.4 Example: Transitioning to Modules—Header Units 16.5 Example: Creating and Using a Module 16.6 Global Module Fragment 16.7 Separating Interface from Implementation 16.8 Partitions 16.9 Additional Modules Examples 16.10 Modules Can Reduce Translation Unit Sizes and Compilation Times 16.11 Migrating Code to Modules 16.12 Future of Modules and Modules Tooling 16.13 Wrap-Up Chapter 17. Concurrent Programming; Intro to C++20
  • 18. Coroutines Part 6: Other Topics Chapter 18. Stream I/O; C++20 Text Formatting: A Deeper Look Chapter 19. Other Topics; A Look Toward C++23 and Contracts Part 7: Appendices Appendix A: Operator Precedence and Grouping Appendix B: Character Set Appendix C: Fundamental Types Appendix D: Number Systems Appendix E: Preprocessor Appendix F: Bits, Characters, C Strings and structs Appendix G: C Legacy Code Topics Appendix H: Using the Visual Studio Debugger Appendix I: Using the GNU C++ Debugger Appendix J: Using the Xcode Debugger
  • 19. Preface Welcome to the C++ programming language and C++20 for Programmers. This book presents leading-edge computing technologies for software developers. These are exciting times in the programming-languages community with each of the major languages striving to keep pace with compelling new programming technologies. The ISO C++ Standards Committee now releases a new standard every three years and the compiler vendors implement the new features promptly. C++20 for Programmers is based on the new C++20 standard. Live-Code Approach At the heart of the book is the Deitel signature live-code approach. We present most concepts in the context of complete working programs followed by one or more sample executions. Read the Before You Begin section that follows this Preface to learn how to set up your Windows, macOS or Linux computer to run the hundreds of code examples. All the source code is available at https://www.deitel.com/c-plus-plus-20-for-programmers We recommend that you compile and run each program as you study it. “Rough-Cut” E-Book for O’Reilly Online Learning Subscribers You are viewing an early-access “rough cut” of C++20 for Programmers. We prepared this content carefully, but it has not yet been reviewed or copy edited and is subject to change. As we complete each chapter, we’ll post it here. Please send any corrections, comments, questions and suggestions for improvement to paul@deitel.com and I’ll respond promptly. Check here frequently for updates. “Sneak Peek” Videos for O’Reilly Online Learning Subscribers
  • 20. As an O’Reilly Online Learning subscriber, you also have access to the “sneak peek” of our new C++20 Fundamentals LiveLessons videos at: https://learning.oreilly.com/videos/c-20-fundamentals-part Co-author Paul Deitel immediately records each video lesson as we complete each rough-cut e-book chapter. Lessons go live on O’Reilly Online Learning a few days later. Again, check here frequently for updates. Modern C++ 20 The C++ programming language is popular for developing systems software, embedded systems, operating systems, real-time systems, computer games, communications systems and other high-performance computer applications. C++20 for Programmers is an introductory-through- intermediate-level, professional tutorial presentation of C++. The book is not a full-language reference manual, nor is it a “cookbook.” We focus on Modern C++, which consists of the four most recent C++ standards—C++11, C++14, C++17 and C++20. Throughout the book, features from these standards are marked with icons in the margins like the 20 icon shown here. Compilers We tested every program in the book on three popular free compilers: • Visual C++ in Microsoft Visual Studio Community edition on Windows, • Clang in Xcode on macOS, and • GNU C++ on Linux and in the GNU Compiler Collection (GCC) Docker container. At the time of this writing, some C++20 features are fully implemented in all three compilers, some are implemented in a subset of the three and some are not implemented at all. We point out these issues as appropriate and will update our online content as the compiler vendors implement the rest of C++20’s features. C++20 compiler support for many more compilers is tracked at https://en.cppreference.com/w/cpp/compiler_support
  • 21. We’ll also post updates on the book’s website at https://deitel.com/books/c-plus-plus-20-for-programmers Target Audiences C++20 for Programmers and our C++20 Fundamentals LiveLessons videos have several target audiences: • Non-C++ software developers who are about to do a C++ project and want to learn the latest version of the language, C++20, in the context of a professional-style, language tutorial. • Software developers who may have learned C++ in college or used it professionally some time ago and want to refresh their C++ knowledge in the context of C++20. • C++ software developers who want to learn C++20 in the context of a professional-style, language tutorial. PERF Security Focus on Performance and Security Issues Throughout the book, we call your attention to performance and security issues with the icons you see here in the margin. “Objects Natural” Learning Approach In your C++ programs, you’ll create and use many objects of carefully- developed-and-tested preexisting classes that enable you to perform significant tasks with minimal code. These classes typically come from: • the C++ Standard Library, • platform-specific libraries, such as those provided by Microsoft Windows, Apple macOS or various Linux versions, • free third-party C++ libraries, often created by the open-source community, and • libraries created by fellow developers, such as those in your organization. To help you appreciate this style of programming, early in the book you’ll create and use objects of preexisting classes before creating your own custom
  • 22. classes in later chapters. We call this the “objects natural” approach. Our “Objects Natural” Learning Approach evolved organically as we worked on our Python for Programmers book (https://learning.oreilly.com/library/view/python- for-programmers/9780135231364/) and our Python Fundamentals LiveLessons videos (https://learning.oreilly.com/videos/python- fundamentals/9780135917411), but C++20 for Programmers is the first book in which we’re using the term, “Objects Natural.” “Rough-Cut” Table of Contents (Subject to Change) Part 1: C++ Fundamentals Quickstart 1. Introduction and Test-Driving a C++ Application 2. Introduction to C++ Programming 3. Control Statements, Part 1; Intro to C++20 Text Formatting 4. Control Statements, Part 2 5. Functions Part 2: Arrays, Pointers, Strings and Files 6. array, vectors, C++20 Ranges and Functional-Style Programming 7. (Downplaying) Pointers in Modern C++ 8. string, Regular Expressions and Files Part 3: Object-Oriented Programming 9. Classes 10. Inheritance and Polymorphism 11. Operator Overloading 12. Exceptions: A Deeper Look Part 4: Standard Library Containers, Iterators and Algorithms 13. Standard Library Containers and Iterators 14. Standard Library Algorithms; Functional Programming: A Deeper Look Part 5: Advanced Topics 15. C++20 Modules
  • 23. 16. Intro to Custom Templates and C++20 Concepts 17. Concurrent Programming; Intro to C++20 Coroutines Part 6: Other Topics 18. Stream I/O; C++20 Text Formatting: A Deeper Look 19. Other Topics; A Look Toward C++23 and Contracts Part 7: Appendices A. Operator Precedence and Grouping B. Character Set C. Fundamental Types D. Number Systems E. Preprocessor F. Bits, Characters, C Strings and structs G. C Legacy Code Topics H. Using the Visual Studio Debugger I. Using the GNU C++ Debugger J. Using the Xcode Debugger Contacting the Authors As you read the book, if you have questions, we’re easy to reach at deitel@deitel.com or https://deitel.com/contact-us We’ll respond promptly. For book updates, visit https://deitel.com/c-plus-plus-20-for-programmers Join the Deitel & Associates, Inc. Social Media Communities Join the Deitel social media communities on • Facebook®—https://facebook.com/DeitelFan
  • 24. • LinkedIn®—https://bit.ly/DeitelLinkedIn • Twitter®—https://twitter.com/deitel • YouTube®—https://youtube.com/DeitelTV About the Authors Paul J. Deitel, CEO and Chief Technical Officer of Deitel & Associates, Inc., is an MIT graduate with 39 years of experience in computing. Paul is one of the world’s most experienced programming-languages trainers, having taught professional courses to software developers since 1992. He has delivered hundreds of programming courses to academic, industry, government and military clients internationally, including Pearson Education through O’Reilly Online Learning, Cisco, IBM, Siemens, Sun Microsystems (now Oracle), Dell, Fidelity, NASA at the Kennedy Space Center, the National Severe Storm Laboratory, White Sands Missile Range, Rogue Wave Software, Boeing, Nortel Networks, Puma, iRobot, UCLA and many more. He and his co-author, Dr. Harvey M. Deitel, are the world’s best-selling programming-language textbook/professional book/video/webinar authors. Dr. Harvey M. Deitel, Chairman and Chief Strategy Officer of Deitel & Associates, Inc., has 59 years of experience in computing. Dr. Deitel earned B.S. and M.S. degrees in Electrical Engineering from MIT and a Ph.D. in Mathematics from Boston University— he studied computing in each of these programs before they spun off Computer Science. He has extensive college teaching experience, including earning tenure and serving as the Chairman of the Computer Science Department at Boston College before founding Deitel & Associates, Inc., in 1991 with his son, Paul. The Deitels’ publications have earned international recognition, with more than 100 translations published in Japanese, German, Russian, Spanish, French, Polish, Italian, Simplified Chinese, Traditional Chinese, Korean, Portuguese, Greek, Urdu and Turkish. Dr. Deitel has delivered hundreds of programming courses to academic, corporate, government and military clients. About Deitel® & Associates, Inc. Deitel & Associates, Inc., founded by Paul Deitel and Harvey Deitel, is an internationally recognized authoring and corporate training organization, specializing in computer programming languages, object technology, mobile
  • 25. app development and Internet-and-web software technology. The company’s training clients include some of the world’s largest companies, government agencies, branches of the military, and academic institutions. The company offers instructor-led training courses delivered at client sites worldwide on major programming languages. Through its 45-year publishing partnership with Pearson/Prentice Hall, Deitel & Associates, Inc., publishes leading-edge programming textbooks and professional books in print and e-book formats, LiveLessons video courses, O’Reilly Online Learning live webinars and Revel™ interactive multimedia courses. To learn more about Deitel on-site corporate training, visit https://deitel.com/training To request a proposal for on-site, instructor-led training worldwide, write to: deitel@deitel.com Individuals wishing to purchase Deitel books can do so at https://www.amazon.com Bulk orders by corporations, the government, the military and academic institutions should be placed directly with Pearson. For more information, visit https://www.informit.com/store/sales.aspx
  • 26. Part 1: C++ Fundamentals Quickstart
  • 27. Chapter 1. Introduction and Test-Driving a C++ Application
  • 29. Objectives In this chapter, you’ll do one or more of the following: ■ Test-drive a C++20 application in the Visual C++ compiler in Microsoft Visual Studio Community edition on Windows. ■ Test-drive a C++20 application in the Clang compiler in Xcode on macOS. ■ Test-drive a C++20 application in the GNU C++ compiler on Linux. ■ Test-drive a C++20 application in the GNU Compiler Collection (GCC) Docker Container in Docker running natively over Windows 10, macOS and/or Linux. 1.1 Introduction 1.2 Test-Driving a C++20 Application 1.2.1 Compiling and Running a C++20 Application with Visual Studio 2019 Community Edition on Windows 10 1.2.2 Compiling and Running a C++20 Application with Xcode on macOS 1.2.3 Compiling and Running a C++20 Application with GNU C++ on Linux 1.2.4 Compiling and Running a C++20 Application with GNU C++ in the GCC Docker Container in Docker Running Natively Over Windows 10, macOS and/or Linux 1.1 Introduction Welcome to C++—one of the world’s most widely used, high-performance, computer-programming languages—and its current version C++20. If you’re reading this, you’re on the O’Reilly Online Learning platform (formerly called Safari) viewing an early-access Rough Cut of our forthcoming book C++20 for Programmers, scheduled for publication this summer. We have prepared this content carefully, but it has not yet been peer reviewed or copy edited and is subject to change. When we complete this chapter, we’ll post the reviewed and copy edited version here.
  • 30. Please send any corrections, comments, questions and suggestions for improvement to paul@deitel.com and I’ll respond promptly. Check for updates here and on the book’s web page: https://deitel.com/c-plus-plus-20-for-programmers This book is written for developers using one or more of the following popular desktop platforms—Microsoft Windows 10, macOS and Linux. We tested every program on three popular free compilers: • Visual C++ in Microsoft Visual Studio Community edition on Windows 10, • Clang in Xcode on macOS, and • GNU C++ on Linux and in the GNU Compiler Collection (GCC) Docker container.1 1. At Deitel, we use current, powerful multicore Apple Mac computers that enable us to run macOS natively, and Windows 10 and Linux through virtual machines in VMWare Fusion. Docker runs natively on Windows, macOS and Linux systems. This early-access version of Chapter 1 contains test-drives demonstrating how to compile and run a C++20 application using these compilers and platforms. The published version of this chapter will contain additional introductory material. At the time of this writing, some C++20 features are fully implemented in all three compilers, some are implemented in a subset of the three and some are not implemented at all. We point out these issues as appropriate and will update our online content as the compiler vendors implement the rest of C++20’s features. C++20 compiler support for many more compilers is tracked at: https://en.cppreference.com/w/cpp/compiler_support “Sneak Peek” Videos for O’Reilly Online Learning Subscribers As an O’Reilly Online Learning subscriber, you also have access to the “sneak peek” of our new C++20 Fundamentals LiveLessons videos at: https://learning.oreilly.com/videos/c-20-fundamentals-part
  • 31. Co-author Paul Deitel immediately records each video lesson as we complete the corresponding chapter. Lessons go live on O’Reilly Online Learning a few days later. Again, check here frequently for updates. 1.2 Test-Driving a C++20 Application In this section, you’ll compile, run and interact with your first C++ application—a guess-the-number game, which picks a random number from 1 to 1000 and prompts you to guess it. If you guess correctly, the game ends. If you guess incorrectly, the application indicates whether your guess is higher or lower than the correct number. There’s no limit on the number of guesses you can make. Usually, this application randomly selects the correct answer as you execute the program. We’ve disabled that aspect of the application so that it uses the same correct answer every time the program executes (though this may vary by compiler). So, you can use the same guesses we use and see the same results. Summary of the Test-Drives We’ll demonstrate running a C++ application using: • Microsoft Visual Studio 2019 Community edition for Windows (Section 1.2.1) • Clang in Xcode on macOS (Section 1.2.2). • GNU C++ in a shell on Linux (Section 1.2.3) • GNU C++ in a shell running inside the GNU Compiler Collection (GCC) Docker container. This requires Docker to be installed and running. You need to read only the section that corresponds to your platform. At the time of this writing, GNU C++ supports the most C++20 features of the three compilers we use. 1.2.1 Compiling and Running a C++20 Application with Visual Studio 2019 Community Edition on Windows 10 In this section, you’ll run a C++ program on Windows using Microsoft Visual Studio 2019 Community edition. There are several versions of Visual Studio available—on some versions, the options, menus and instructions we
  • 32. present might differ slightly. From this point forward, we'll simply say “Visual Studio” or “the IDE.” Step 1: Checking Your Setup If you have not already done so, read the Before You Begin section of this book for instructions on installing the IDE and downloading the book’s code examples. Step 2: Launching Visual Studio Open Visual Studio from the Start menu. The IDE displays the following Visual Studio 2019 window containing: Close this window for now by clicking the X in its tab—you can access this window any time by selecting File > Start Window. We use the > character to indicate selecting a menu item from a menu. For example, the notation File > Open indicates that you should select the Open menu item from the File menu.
  • 33. Step 3: Creating a Project A project is a group of related files, such as the C++ source-code files that compose an application. Visual Studio organizes applications into projects and solutions, which contain one or more projects. Multiple-project solutions are used to create large-scale applications. Each application in this book requires only a single-project solution. To work our code examples, you’ll begin with an Empty Project and add files to it. To create a project: 1. Select File > New > Project… to display the Create a New Project dialog: 2. In the preceding dialog, select the Empty Project template with the tags C++, Windows and Console. This template is for programs that execute at the command line in a Command Prompt window.
  • 34. Depending on the version of Visual Studio you’re using and the options you have installed, there may be many other project templates installed. You can narrow down your choices using the Search for templates textbox and the drop-down lists below it. Click Next to display the Configure your new project dialog: 3. Provide a Project name and Location for your project. For the Project name, we specified cpp20_test. For the Location, we selected the examples folder containing this book’s code examples. Click Create to open your new project in Visual Studio. At this point, the Visual Studio creates your project, places its folder in C:UsersYourUserAccountDocumentsexamples (or the folder you specified) and opens the main window:
  • 35. This window displays editors as tabbed windows (one for each file) when you’re editing code. On the left side is the Solution Explorer for viewing and managing your application’s files. In this book’s examples, you’ll typically place each program’s code files in the Source Files folder. If the Solution Explorer is not displayed, you can display it by selecting View > Solution Explorer. Step 4: Adding the GuessNumber.cpp File into the Project Next, you’ll add GuessNumber.cpp to the project you created in Step 3. In the Solution Explorer: 1. Right-click the Source Files folder and select Add > Existing Item…. 2. In the dialog that appears, navigate to the ch01 subfolder of the book’s examples folder, GuessNumber.cpp and click Add.2 2. For the multiple source-code-file programs that you’ll see in later chapters, select all the files for a given program. When you begin creating programs yourself, you can right click the Source Files folder and select Add > New Item… to display a dialog for adding a new file. Step 5: Configuring Your Project to Use C++20 The Visual C++ compiler in Visual Studio supports several versions of the C++ standard. For this book, we use C++20, which we must configure in our project’s settings:
  • 36. 1. Right-click the project’s node— —in the Solution Explorer and select Properties to display the project’s cpp20_test Property Pages dialog: 2. In the left column, expand the C/C++ node, then select Language. 3. In the right column, click in the field to the right of C++ Language Standard, click the down arrow, then select Preview - Features from the Latest C++ Working Draft (/std:c++latest) and click OK. In a future version of Visual Studio, Microsoft will change this option to ISO C++20 Standard (/std:c++20). Step 6: Compiling and Running the Project To compile and run the project so you can test-drive the application, select Debug > Start without debugging or type Ctrl + F5. If the program
  • 37. compiles correctly, Visual Studio opens a Command Prompt window and executes the program. We changed the Command Prompt’s color scheme and font size for readability: Step 7: Entering Your First Guess At the ? prompt, type 500 and press Enter. The application displays "Too high. Try again." to indicate the value you entered is greater than the number the application chose as the correct guess: Step 8: Entering Another Guess At the next prompt, type 250 and press Enter. The application displays "Too high. Try again.", because the value you entered once again is greater than the correct guess:
  • 38. Step 9: Entering Additional Guesses Continue to play the game by entering values until you guess the correct number. When you guess correctly, the application displays "Excellent! You guessed the number!": Step 10: Playing the Game Again or Exiting the Application After you guess the correct number, the application asks if you’d like to play another game. At the "Would you like to play again (y or n)?" prompt, entering y causes the application to choose a new number and start a new game. Entering n terminates the application. Each time you
  • 39. execute this application from the beginning (Step 6), it will choose the same numbers for you to guess. Reusing This Project for Subsequent Examples You can follow the steps in this section to create a separate project for every application in the book. However, for our examples, you may find it more convenient to remove the current program from the project then add a new one. To remove a file from your project (but not your system), select it in the Solution Explorer then press Del (or Delete). You can then repeat Step 4 to add a different program to the project. 1.2.2 Compiling and Running a C++20 Application with Xcode on macOS In this section, you’ll run a C++ program on a macOS using the Clang compiler in Apple’s Xcode IDE. Step 1: Checking Your Setup If you have not already done so, read the Before You Begin section of this book for instructions on installing the IDE and downloading the book’s code examples. Step 2: Launching Xcode Open a Finder window, select Applications and double-click the Xcode icon ( ). If this is your first time running Xcode, the Welcome to Xcode window appears:
  • 40. Close this window by clicking the X in the upper left corner—you can access it any time by selecting Window > Welcome to Xcode. We use the > character to indicate selecting a menu item from a menu. For example, the notation File > Open… indicates that you should select the Open… menu item from the File menu. Step 3: Creating a Project A project is a group of related files, such as the C++ source-code files that compose an application. The Xcode projects we created for this book’s examples are Command Line Tool projects that you’ll execute directly in the IDE. To create a project: 1. Select File > New > Project…. 2. At the top of the Choose a template for your new project dialog, click macOS. 3. Under Application, click Command Line Tool and click Next. 4. For Product Name, enter a name for your project—we specified cpp20_test. 5. In the Language drop-down list, select C++ then click Next.
  • 41. 6. Specify where you want to save your project. We selected the examples folder containing this book’s code examples. 7. Click Create. Xcode creates your project and displays the workspace window initially showing three areas—the Navigator area, Editor area and Utilities area: The left-side Navigator area has icons at its top for the navigators that can be displayed there. For this book, you’ll primarily work with • Project ( )—Shows all the files and folders in your project. • Issue ( )—Shows you warnings and errors generated by the compiler. Clicking a navigator button displays the corresponding navigator panel. The middle Editor area is for managing project settings and editing source code. This area is always displayed in your workspace window. Selecting a file in the Project navigator, the file’s contents display in the Editor area. You will not use the right-side Utilities area in this book. There’s also a Debug area in which you’ll run and interact with the guess-the-number program. This will appear below the Editor area. The workspace window’s toolbar contains options for executing a program:
  • 42. displaying the progress of tasks executing in Xcode: and hiding or showing the left (Navigator), right (Utilities) and bottom (Debug) areas: Step 4: Configuring the Project to Compile Using C++20 The Clang compiler in Xcode supports several versions of the C++ standard. For this book, we use C++20, which we must configure in our project’s settings: 1. In the Project navigator, select your project’s name (cpp20_test). 2. In the Editors area’s left side, select your project’s name under TARGET. 3. At the top of the Editors area, click Build Settings, and just below it, click All. 4. Scroll to the Apple Clang - Language - C++ section. 5. Click the value to the right of C++ Language Dialect and select Other…. 6. In the popup area, replace the current setting with c++2a and press Enter. In a future version of Xcode, Apple will provide a C++20 option for C++ Language Dialect. Step 5: Deleting the main.cpp File from the Project By default, Xcode creates a main.cpp source-code file containing a simple program that displays "Hello, World!". You won’t use main.cpp in this test-drive, so you should delete the file. In the Project navigator, right- click the main.cpp file and select Delete. In the dialog that appears, select Move to Trash. The file will not be removed from your system until you empty your trash.
  • 43. Step 6: Adding the GuessNumber.cpp File into the Project In a Finder window, open the ch01 folder in the book’s examples folder, then drag GuessNumber.cpp onto the Guess Number folder in the Project navigator. In the dialog that appears, ensure that Copy items if needed is checked, then click Finish.3 3. For the multiple source-code-file programs that you’ll see later in the book, drag all the files for a given program to the project’s folder. When you begin creating your own programs, you can right click the project’s folder and select New File… to display a dialog for adding a new file. Step 7: Compiling and Running the Project To compile and run the project so you can test-drive the application, simply click the run ( ) button on Xcode’s toolbar. If the program compiles correctly, Xcode opens the Debug area and executes the program in the right half of the Debug area: The application displays "Please type your first guess.", then displays a question mark (?) as a prompt on the next line. Step 8: Entering Your First Guess Click in the Debug area, then type 500 and press Return The application displays "Too low. Try again.", meaning that the value you entered is less than the number the application chose as the correct guess. Step 9: Entering Another Guess
  • 44. At the next prompt, enter 750: The application displays "Too low. Try again.", because the value you entered once again is less than the correct guess. Step 10: Entering Additional Guesses Continue to play the game by entering values until you guess the correct number. When you guess correctly, the application displays "Excellent! You guessed the number.": Playing the Game Again or Exiting the Application After you guess the correct number, the application asks if you’d like to play another game. At the "Would you like to play again (y or n)?" prompt, entering y causes the application to choose a new number and start a new game. Entering n terminates the application. Each time you execute this application from the beginning (Step 7), it will choose the same numbers for you to guess.
  • 45. Reusing This Project for Subsequent Examples You can follow the steps in this section to create a separate project for every application in the book. However, for our examples, you may find it more convenient to remove the current program from the project then add a new one. To remove a file from your project (but not your system), right-click the file in the Project navigator and select Delete. In the dialog that appears, select Move to Trash. You can then repeat Step 6 to add a different program to the project. 1.2.3 Compiling and Running a C++20 Application with GNU C++ on Linux For this test drive, we assume that you read the Before You Begin section and that you placed the downloaded examples in your user account’s Documents folder. Step 1: Changing to the ch01 Folder From a Linux shell, use the cd command to change to the ch01 subfolder of the book’s examples folder: Click here to view code image ~$ cd ~/Documents/examples/ch01 ~/Documents/examples/ch01$ In this section’s figures, we use bold to highlight the text that you type. The prompt in our Ubuntu Linux shell uses a tilde (~) to represent the home directory. Each prompt ends with the dollar sign ($). The prompt may differ on your Linux system. Step 2: Compiling the Application Before running the application, you must first compile it: Click here to view code image ~/Documents/examples/ch01$ g++ -std=c++2a GuessNumber.cpp - ~/Documents/examples/ch01$
  • 46. The g++ command compiles the application: • The -std=c++2a option indicates that we’re using C++20—c++2a will become c++20 in a future GNU C++ release. • The -o option names the executable file (GuessNumber) that you’ll use to run the program. Step 3: Running the Application Type ./GuessNumber at the prompt and press Enter to run the program: Click here to view code image ~/Documents/examples/ch01$ ./GuessNumber I have a number between 1 and 1000. Can you guess my number? Please type your first guess. ? The ./ tells Linux to run a file from the current directory and is required to indicate that GuessNumber is an executable file. Step 4: Entering Your First Guess The application displays "Please type your first guess.", then displays a question mark (?) as a prompt on the next line. At the prompt, enter 500—note that the outputs may vary based on the compiler you’re using: Click here to view code image ~/Documents/examples/ch01$ ./GuessNumber I have a number between 1 and 1000. Can you guess my number? Please type your first guess. ? 500 Too high. Try again. ?
  • 47. The application displays "Too high. Try again.", meaning that the value you entered is greater than the number the application chose as the correct guess. Step 5: Entering Another Guess At the next prompt, enter 250: Click here to view code image ~/Documents/examples/ch01$ ./GuessNumber I have a number between 1 and 1000. Can you guess my number? Please type your first guess. ? 500 Too high. Try again. ? 250 Too low. Try again. ? This time the application displays "Too low. Try again.", because the value you entered is less than the correct guess. Step 6: Entering Additional Guesses Continue to play the game by entering values until you guess the correct number. When you guess correctly, the application displays "Excellent! You guessed the number.": Click here to view code image Too low. Try again. ? 375 Too low. Try again. ? 437 Too high. Try again. ? 406 Too high. Try again. ? 391
  • 48. Too high. Try again. ? 383 Too low. Try again. ? 387 Too high. Try again. ? 385 Too high. Try again. ? 384 Excellent! You guessed the number. Would you like to play again (y or n)? Step 7: Playing the Game Again or Exiting the Application After you guess the correct number, the application asks if you’d like to play another game. At the "Would you like to play again (y or n)?" prompt, entering y causes the application to choose a new number and start a new game. Entering n terminates the application and returns you to the shell. Each time you execute this application from the beginning (Step 3), it will choose the same numbers for you to guess. 1.2.4 Compiling and Running a C++20 Application with GNU C++ in the GCC Docker Container in Docker Running Natively Over Windows 10, macOS and/or Linux At the time of this writing, GNU C++ implements the most C++20 features. For this reason, you may want to use the latest GNU C++ compiler on your system. One of the most convenient cross-platform ways to do this is by using the GNU Compiler Collection (GCC) Docker container. This section assumes you’ve already installed Docker Desktop (Windows or macOS) or Docker Engine (Linux). Executing the GNU Compiler Collection (GCC) Docker Container Open a Command Prompt (Windows), Terminal (macOS/Linux) or shell (Linux), then perform the following steps to launch the GCC Docker Container: 1. Use the cd command to navigate to the examples folder containing this book’s examples.
  • 49. Discovering Diverse Content Through Random Scribd Documents
  • 50. Fig. 34—Showing how to force glass blowpipe (A) into vitreous (B). (Page 80.)
  • 51. Fig. 35—Showing bulging out of vitreous caused by blowing air through glass blowpipe. (Page 80.)
  • 52. Fig. 36—Showing the vitreous (A) removed. Holding the eye suspended by its optic nerve, force the glass blowpipe through the vitreous until it all but touches the posterior part of the retina (Fig. 34); blow gently at first, increasing the pressure until the vitreous suddenly bulges outward. (Fig. 35.) If the iris has been cut away close to the ora serrata, the vitreous will not only bulge forward, but it will fall out. If, however, it does not detach itself at once, insert the scalpel close to the choroid and with its flat side press downward until a separation occurs. Do not let the vitreous drop out too suddenly, because it may tear the retina. Let the vitreous detach itself slowly by the force of its own weight, though it will be well to hold some of its weight on the scalpel. (Fig. 36.)
  • 53. Fig. 37—A. Showing retina folded upon itself by blowing air at it through the glass blowpipe. (Page 83.)
  • 54. Fig. 38—A. Showing folded retina suspended from its attachment, so sclerotic and choroid may be easily cut away. (Page 83.) After the vitreous has been removed, turn the eye upward, and by blowing strongly through the blowpipe at the marginal edge of the retina, turn the retina upon itself. Repeat this until the retina lies in a small wrinkled lump at the “bottom” of the posterior part of the eye. (Fig. 37.) Invert the eye (Fig. 38) and cut away both the choroid and the sclerotic close to the optic nerve. No care need be taken in doing this until the scissors come close to the optic nerve. (Fig. 39.)
  • 55. Fig. 39—Showing the sclerotic nearly all cut away.
  • 56. Fig. 40—Isolated retina, with optic nerve attached. After the choroid and the sclerotic have been cut away, drop the retina into some water, and it will slowly unfold itself by “ballooning” out into a perfect and beautiful specimen. (Fig. 40.) But, if it is desired to study the specimen closely, it is better to suspend it in a jar or bottle made of thin glass, and containing a 5 per cent. solution of formaldehyde. Remember that the retina is a delicate membrane in any state; the slightest rough handling may cause it to be torn, or otherwise damaged. If the vessel, in which the specimen has been placed and suspended, has enough preserving fluid to completely fill it, and it is firmly stoppered, the whole thing may be inverted, and turned in any direction, even abruptly, without fear of damaging the retina. This way of keeping the retina will give opportunity to inspect and study the inside as well as the outside of the membrane; the blood-vessels, and other important parts easily recognized.
  • 58. THE SAGITTAL OR VERTICAL SECTION OF THE EYE Place an eye in a 5 per cent. solution of formaldehyde for about two weeks. If the eye is kept in that solution longer than that time, the lens is apt to become so hard that in cutting it the capsule and suspensory ligament will be torn, and the lens will then become detached; if for a shorter space of time, the lens and other tissues will be so soft that all may be so badly torn or lacerated, that a perfect specimen will not be possible. It sometimes happens that in keeping a number of eyes together in a vessel for the purpose of hardening them in the formaldehyde solution, the corneas of some will be crushed in. For this dissection, select an eye that has the cornea in perfect condition. Remove all the outside tissues with the scissors, being particular to have the region immediately surrounding the optic nerve perfectly clear and clean. If the optic nerve is longer than 5 mm., cut it off to that length.
  • 59. Fig. 41—Showing the beginning of the cutting of the eye for sagittal sections.
  • 60. Fig. 42—Showing method of cutting through the crystalline lens. To cut the eye in two, use a safety-razor blade; never a scalpel. The latter is too thick, too dull, and too clumsy a tool. Begin by cutting through the optic nerve; dividing it as nearly as possible into halves. (Fig. 41.) Continue cutting through the sclerotic and all underlying tissues, stopping at the corneo-scleral junction, but do not, during this procedure, even touch the lens. After the eye has been thus partly separated into, as nearly as possible, two equal parts, lay it down upon the cornea, and, holding the razor blade in the forefingers and thumbs of both hands, cut the lens in two by forcing the blade down through it. (Fig. 42.) Partly open the cut eye to allow one jaw of the large scissors to enter, turn the eye over so the cornea will rest on that jaw, and then cut through the cornea. (Fig. 43.)
  • 61. Fig. 43—Showing method of cutting through the cornea and completing the two sagittal sections. The two specimens may be kept indefinitely by placing them in a 3 per cent. formaldehyde solution. It will be well to remove the lens from one of the specimens, because it will give better opportunity to see the anatomical relationships. Also, these specimens should be mounted, one above the other, between two pieces of glass, before placing them in the receptacle that is to hold them. Much can be studied in such specimens. Moreover, they present to view the various parts of the organ of vision in such an impressive way, that one does not soon forget the wonderful appearance of the construction of this, Nature’s perfect camera. (Fig. 44.)
  • 62. Fig. 44—Sagittal section enlarged. If another eye is cut into two parts, additional interesting specimens may be procured; for instance, one showing the presence of the second coat only, the retina having been torn out. Another good specimen may be made by removing all of the inner tissues, and leaving only the sclerotic and cornea. This specimen will show that the first coat is almost entirely a coat which affords strength and protection to the parts that lie within.
  • 64. THE PAPILLA, PUNCTA LACRIMALIA, AND NASAL DUCT The only way to dissect the lacrimal apparatus, other ocular accessories, and the extrinsic muscles, is to procure the head of some animal, preferably a calf’s head, because of its size. Any butcher will supply one for from forty to sixty cents. Have the lower jaw removed. It will make a less bulky piece of material to handle. Close to the inner canthus, on the inner side of each lid, will be found a little rounded eminence—lacrimal papilla—in the centre of which is a small opening—punctum lacrimalis. Both may be seen better on the lower lid, if it is pulled down, and on the upper lid, if it is pulled up.
  • 65. Fig. 45—Showing only a part of a calf’s head and the knitting-needles inserted in the puncta. (Page 94.)
  • 66. Fig. 46. Be supplied with two knitting-needles. Take one, lubricate its full length with a little vaseline, lard, oil, or any other lubricant. Insert the needle into the punctum of the lower lid, and push it downward and forward, aiming to come out in the nose a short distance from its end. At first it may be a little difficult to get the needle started; if so, just wiggle the needle, pushing it at the same time as directed, until the nasal duct is found. Do not remove the needle. To insert the other needle into the punctum of the upper lid is rather difficult; for that reason the punctum of the lower lid was chosen, first. Grease the needle, as was done to the first one, and, with a little patience and careful manipulation, the canal opening and its course
  • 67. will soon be found. The needle may then be pushed through until it meets the first one. (Fig. 45.) From the puncta lacrimalia to the place of meeting of the two needles, marks the course of the two canaliculi and their junction before they merge and form the nasal duct. Leave the needles where they are, and begin cutting away the skin. The needles will then mark the course of each canal and the duct very plainly. With the small scissors the canals and the duct may be loosened from the surrounding tissues. Or, the scalpel may be used to lay open the canals, cutting along over the top of the needles. (Fig. 46.) The cilia, palpebræ, palpebral conjunctiva, ocular conjunctiva, and other superficial ocular accessories may be examined without dissection.
  • 68. MEIBOMIAN GLANDS AND DUCTS An examination of the eyelids will show the openings of the ducts of the meibomian glands a short distance back of the cilia. Very fine pins or needles that have been greased may be easily inserted for a short distance into the ducts, and then a dissection made along the course of the duct as outlined by the presence of the inserted pins or needles. Another way to see the glands is to slice through the ducts, with the scalpel or safety-razor blade, the entire width of either eyelid. This will separate the glands into two parts and show their length, breadth and structure.
  • 69. ENUCLEATION OF THE ORBITAL CONTENTS The eyes one procures from a butcher or a slaughter house will always have the extrinsic tissues so badly cut and torn that identification of the various parts and their relations is impossible. Therefore, it is best to supply one’s self with the head of an animal, such as a sheep or a calf, and dissect an eye with all its extrinsic tissues intact. For this dissection, a hammer and a chisel are necessary in addition to the tools needed for doing the previous dissections. Fig. 47—Showing method of making the initial cuts in the skin. (Page 97.)
  • 70. Fig. 48—Part of calf’s head, showing the first cut to be made in the bones of the orbit. (Page 102.)
  • 71. Welcome to Our Bookstore - The Ultimate Destination for Book Lovers Are you passionate about books and eager to explore new worlds of knowledge? At our website, we offer a vast collection of books that cater to every interest and age group. From classic literature to specialized publications, self-help books, and children’s stories, we have it all! Each book is a gateway to new adventures, helping you expand your knowledge and nourish your soul Experience Convenient and Enjoyable Book Shopping Our website is more than just an online bookstore—it’s a bridge connecting readers to the timeless values of culture and wisdom. With a sleek and user-friendly interface and a smart search system, you can find your favorite books quickly and easily. Enjoy special promotions, fast home delivery, and a seamless shopping experience that saves you time and enhances your love for reading. Let us accompany you on the journey of exploring knowledge and personal growth! ebookgate.com