C++17 Quick Syntax Reference: A Pocket Guide to the Language, APIs and Library
()
About this ebook
In the C++17 Quick Syntax Reference, you will find short, simple, and focused code examples. This book includes a well laid out table of contents and a comprehensive index allowing for easy review. You won’t find any technical jargon, bloated samples, drawn out history lessons, or witty stories in this book. What you will find is a language reference that is concise, to the point and highly accessible. The book is packed with useful information and is a must-have for any C++ programmer.
What You'll Learn
- Use template argument deduction for class templates
- Declare non-type template parameters with auto-folding expressions and auto deduction from braced-init-list
- Apply lambdas and lambda capture by value
- Work with inline variables, nested namespaces, structured bindings, and selection statements with initializer
- Use utf-8 character literals
- Carry out direct-list initialization of enums
- Use these new C++17 library features or class templates from std::variant, optional, any, string_view, invoke, apply and more
- Do splicing for maps and sets, also new to C++17
Who This Book Is For
Experienced C++ programmers. Additionally, this is a concise, easily-digested introduction for other programmers new to C++.
Mikael Olsson
Mikael Olsson is a professional programmer, author and web entrepreneur. He enjoys teaching, writing books and making sites that summarize various fields of interest. The books he writes are focused on teaching their subject in the most efficient way possible, by explaining only what is relevant and practical without any unnecessary repetition or theory. He can be reached online at Siforia.com.
Read more from Mikael Olsson
Java 17 Quick Syntax Reference: A Pocket Guide to the Java SE Language, APIs, and Library Rating: 0 out of 5 stars0 ratingsHandbook of Success: How to Make your Life What you Want it to Be Rating: 5 out of 5 stars5/5Java Quick Syntax Reference Rating: 0 out of 5 stars0 ratingsPHP 8 Quick Scripting Reference: A Pocket Guide to PHP Web Scripting Rating: 0 out of 5 stars0 ratingsCSS Quick Syntax Reference Rating: 0 out of 5 stars0 ratingsC# 7 Quick Syntax Reference: A Pocket Guide to the Language, APIs, and Library Rating: 0 out of 5 stars0 ratingsC# 8 Quick Syntax Reference: A Pocket Guide to the Language, APIs, and Library Rating: 0 out of 5 stars0 ratingsC++20 Quick Syntax Reference: A Pocket Guide to the Language, APIs, and Library Rating: 0 out of 5 stars0 ratingsModern C Quick Syntax Reference: A Pocket Guide to the Language, APIs, and Library Rating: 0 out of 5 stars0 ratingsCSS3 Quick Syntax Reference: A Pocket Guide to the Cascading Style Sheets Language Rating: 0 out of 5 stars0 ratings
Related to C++17 Quick Syntax Reference
Related ebooks
Programming with 64-Bit ARM Assembly Language: Single Board Computer Development for Raspberry Pi and Mobile Devices Rating: 0 out of 5 stars0 ratingsBeginning JavaScript: The Ultimate Guide to Modern JavaScript Development Rating: 0 out of 5 stars0 ratingsPro TypeScript: Application-Scale JavaScript Development Rating: 4 out of 5 stars4/5RP2040 Assembly Language Programming: ARM Cortex-M0+ on the Raspberry Pi Pico Rating: 0 out of 5 stars0 ratingsClean C++20: Sustainable Software Development Patterns and Best Practices Rating: 0 out of 5 stars0 ratingsLearn C++ for Game Development Rating: 0 out of 5 stars0 ratingsIntroducing Bootstrap 4: Create Powerful Web Applications Using Bootstrap 4.5 Rating: 0 out of 5 stars0 ratingsDesign Patterns in Modern C++: Reusable Approaches for Object-Oriented Software Design Rating: 0 out of 5 stars0 ratingsBeginning C++20: From Novice to Professional Rating: 0 out of 5 stars0 ratingsC# Deconstructed: Discover how C# works on the .NET Framework Rating: 0 out of 5 stars0 ratingsRaspberry Pi Assembly Language Programming: ARM Processor Coding Rating: 0 out of 5 stars0 ratingsVisual Studio Condensed: For Visual Studio 2013 Express, Professional, Premium and Ultimate Editions Rating: 0 out of 5 stars0 ratingsSwift 3 Object-Oriented Programming - Second Edition Rating: 0 out of 5 stars0 ratingsLighttpd Rating: 4 out of 5 stars4/5Pattern-Oriented Software Architecture, On Patterns and Pattern Languages Rating: 5 out of 5 stars5/5Practical C++20 Financial Programming: Problem Solving for Quantitative Finance, Financial Engineering, Business, and Economics Rating: 0 out of 5 stars0 ratingsBeginning Backbone.js Rating: 3 out of 5 stars3/5Advanced Excel Essentials Rating: 2 out of 5 stars2/5Minimalist Mobile Robotics Rating: 0 out of 5 stars0 ratingsHello World: Student to Software Professional - a Transformation Guide Rating: 0 out of 5 stars0 ratingsRust for the IoT: Building Internet of Things Apps with Rust and Raspberry Pi Rating: 0 out of 5 stars0 ratingsC++ Functions and tutorial Rating: 0 out of 5 stars0 ratingsLearn Java for Web Development: Modern Java Web Development Rating: 0 out of 5 stars0 ratingsSimultaneous multithreading A Complete Guide Rating: 0 out of 5 stars0 ratingsDesign Patterns in C#: A Hands-on Guide with Real-world Examples Rating: 0 out of 5 stars0 ratingsPractical Scientific Computing Rating: 0 out of 5 stars0 ratingsPatterns in the Machine: A Software Engineering Guide to Embedded Development Rating: 5 out of 5 stars5/5Regex Quick Syntax Reference: Understanding and Using Regular Expressions Rating: 0 out of 5 stars0 ratingsC Clearly - Programming With C In Linux and On Raspberry Pi Rating: 0 out of 5 stars0 ratingsFoundation Course for Advanced Computer Studies Rating: 0 out of 5 stars0 ratings
Programming For You
Python: For Beginners A Crash Course Guide To Learn Python in 1 Week Rating: 4 out of 5 stars4/5Python: Learn Python in 24 Hours Rating: 4 out of 5 stars4/5Java for Beginners: A Crash Course to Learn Java Programming in 1 Week Rating: 5 out of 5 stars5/5SQL: For Beginners: Your Guide To Easily Learn SQL Programming in 7 Days Rating: 5 out of 5 stars5/5Game Development with Unreal Engine 5: Learn the Basics of Game Development in Unreal Engine 5 (English Edition) Rating: 0 out of 5 stars0 ratingsLearn to Code. Get a Job. The Ultimate Guide to Learning and Getting Hired as a Developer. Rating: 5 out of 5 stars5/5HTML & CSS: Learn the Fundaments in 7 Days Rating: 4 out of 5 stars4/5Coding All-in-One For Dummies Rating: 4 out of 5 stars4/5Python Programming : How to Code Python Fast In Just 24 Hours With 7 Simple Steps Rating: 4 out of 5 stars4/5SQL QuickStart Guide: The Simplified Beginner's Guide to Managing, Analyzing, and Manipulating Data With SQL Rating: 4 out of 5 stars4/5Learn HTML Programming in 7 Days: Ultimate Beginners Guide to Build and Design Your Own Website Rating: 4 out of 5 stars4/5Data Structures and Algorithm Analysis in Java, Third Edition Rating: 4 out of 5 stars4/5Python for Beginners: Learn the Fundamentals of Computer Programming Rating: 0 out of 5 stars0 ratingsExcel : The Ultimate Comprehensive Step-By-Step Guide to the Basics of Excel Programming: 1 Rating: 5 out of 5 stars5/5PYTHON: Practical Python Programming For Beginners & Experts With Hands-on Project Rating: 5 out of 5 stars5/5Learn SQL in 24 Hours Rating: 5 out of 5 stars5/5Beginning Programming with Python For Dummies Rating: 3 out of 5 stars3/5Grokking Algorithms: An illustrated guide for programmers and other curious people Rating: 4 out of 5 stars4/5C++ Learn in 24 Hours Rating: 0 out of 5 stars0 ratingsLinux: Learn in 24 Hours Rating: 5 out of 5 stars5/5Learn JavaScript in 24 Hours Rating: 3 out of 5 stars3/5
Reviews for C++17 Quick Syntax Reference
0 ratings0 reviews
Book preview
C++17 Quick Syntax Reference - Mikael Olsson
© Mikael Olsson 2018
Mikael OlssonC++17 Quick Syntax Referencehttps://doi.org/10.1007/978-1-4842-3600-0_1
1. Hello World
Mikael Olsson¹
(1)
Hammarland, Finland
Choosing an IDE
To begin developing in C++ you need a text editor and a C++ compiler. You can get both at the same time by installing an Integrated Development Environment (IDE) that includes support for C++. A good choice is Microsoft's Visual Studio Community Edition, which is a free version of Visual Studio that is available from Microsoft’s website.¹ This IDE has full support for the C++14 standard and includes most features of C++17 as of the 2017 version.
Two other popular cross-platform IDEs include NetBeans and Eclipse CDT. Alternatively, you can develop using a simple text editor such as Notepad, although this is less convenient than using an IDE. If you choose to use a simple text editor, just create an empty document with a .cpp file extension and open it in the editor of your choice.
Creating a Project
After installing Visual Studio, go ahead and launch the program. You then need to create a project, which will manage the C++ source files and other resources. Go to File ➤ New ➤ Project in Visual Studio to display the New Project window. From there, select the Visual C++ template type in the left frame. Then select the Empty Project template in the right frame. At the bottom of the window, you can configure the name and location of the project. When you are finished, click the OK button to let the wizard create your empty project.
Adding a Source File
You have now created a C++ project. In the Solution Explorer pane (choose View ➤ Solution Explorer), you can see that the project consists of three empty folders: Header Files, Resource Files, and Source Files. Right-click on the Source Files folder and choose Add ➤ New Item. From the Add New Item dialog box, choose the C++ file (.cpp) template. Give this source file the name MyApp and click the Add button. An empty .cpp file will now be added to your project and opened for you.
Selecting Language Standard
To enable the latest features of the C++ language outlined in this book it is necessary to manually change the language standard setting for your project. You can do this by first going to Project ➤ Properties to bring up the Property pages. From there, navigate to Configuration Properties ➤ C/C++ ➤ Language ➤ C++ Language Standard. Select the ISO C++17 standard from the drop-down list. Click OK and the project will now be configured to compile according to the C++17 language standard.
Hello World
The first thing to add to the source file is the main() function. This is the entry point of the program, and the code inside of the curly brackets is executed when the program runs. The brackets, along with their content, is referred to as a code block, or just a block.
int main() {}
The first application will simply output the text Hello World
to the screen. Before this can be done the iostream header needs to be included. This header provides input and output functionality for the program, and it is one of the standard library files that comes with all C++ compilers. The #include directive effectively replaces the line with everything in the specified header before the file is compiled into an executable.
#include
int main() {}
With iostream included, you gain access to several new functions. These are all located in the standard namespace called std, which you can examine by using a double colon, also called the scope resolution operator (:: ) . After typing this in Visual Studio, the IntelliSense window will automatically open, displaying the namespace contents. Among the members you find the cout stream, which is the standard output stream in C++ that will be used to print text to a console window. It uses two less than signs, collectively known as the insertion operator (<<), to indicate what to output. The string can then be specified, delimited by double quotes, and followed by a semicolon. The semicolon is used in C++ to mark the end of all statements.
#include
int main()
{
std::cout << Hello World
;
}
Using the Standard Namespace
To make things a bit easier, you can add a line specifying that the code file uses the standard namespace. You then no longer have to prefix cout with the namespace (std::) since it is used by default.
#include
using namespace std;
int main()
{
cout << Hello World
;
}
IntelliSense
When writing code in Visual Studio, a window called IntelliSense will pop up wherever there are multiple predetermined alternatives from which to choose. This window can be also brought up manually at any time by pressing Ctrl+Space to provide quick access to any code entities you are able to use within your program. This is a very powerful feature that you should learn to make good use of.
Footnotes
1
http://www.microsoft.com/visualstudio
© Mikael Olsson 2018
Mikael OlssonC++17 Quick Syntax Referencehttps://doi.org/10.1007/978-1-4842-3600-0_2
2. Compile and Run
Mikael Olsson¹
(1)
Hammarland, Finland
Visual Studio Compilation
Continuing from the last chapter, the Hello World program is now complete and ready to be compiled and run. You can do this by going to the Debug menu and clicking on Start Without Debugging (Ctrl+F5). Visual Studio then compiles and runs the application, which displays the text in a console window.
If you select Start Debugging (F5) from the Debug menu instead, the console window displaying Hello World will close as soon as the main function is finished. To prevent this, you can add a call to the cin.get function at the end of main. This function, belonging to the console input stream, will read input from the keyboard until the Return key is pressed.
#include
using namespace std;
int main()
{
cout << Hello World
;
cin.get();
}
Console Compilation
As an alternative to using an IDE, you can also compile source files from a terminal window as long as you have a C++ compiler.¹ For example, on a Linux machine you can use the GNU C++ compiler, which is available on virtually all UNIX systems, including Linux and the BSD family, as part of the GNU Compiler Collection (GCC) . This compiler can also be installed on Windows by downloading MinGW or on the Mac as part of the Xcode development environment.
To use the GNU compiler, you type its name g++ in a terminal window and give it the input and output filenames as arguments. It then produces an executable file, which when run gives the same result as the one compiled under Windows in Visual