Share E-Book

C++ 20 Quick Syntax Reference A Pocket Guide to the Language, APIs, and Library (Mikael Olsson) (Z-Library)

Author Mikael Olsson

science
Language English

No Description

Format PDF
Size 2.1 MB
259
Views
0
Downloads
0.00
Total Donations
(First 20 pages)

Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Page 1
C++20 Quick Syntax Reference A Pocket Guide to the Language, APIs, and Library — Fourth Edition — Mikael Olsson
Page 2
C++20 Quick Syntax Reference A Pocket Guide to the Language, APIs, and Library Fourth Edition Mikael Olsson
Page 3
C++20 Quick Syntax Reference: A Pocket Guide to the Language, APIs, and Library ISBN-13 (pbk): 978-1-4842-5994-8 ISBN-13 (electronic): 978-1-4842-5995-5 https://doi.org/10.1007/978-1-4842-5995-5 Copyright © 2020 by Mikael Olsson This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed. Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights. While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein. Managing Director, Apress Media LLC: Welmoed Spahr Acquisitions Editor: Steve Anglin Development Editor: Matthew Moodie Coordinating Editor: Mark Powers Cover designed by eStudioCalamar Cover image designed by Freepik (www.freepik.com) Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer-sbm.com, or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation. For information on translations, please e-mail editorial@apress.com; for reprint, paperback, or audio rights, please email bookpermissions@springernature.com. Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales web page at http://www.apress.com/bulk-sales. Any source code or other supplementary material referenced by the author in this book is available to readers on GitHub via the book’s product page, located at www.apress.com/9781484259948. For more detailed information, please visit http://www.apress.com/source-code. Printed on acid-free paper Mikael Olsson Hammarland, Finland
Page 4
(This page has no text content)
Page 5
(This page has no text content)
Page 6
(This page has no text content)
Page 7
(This page has no text content)
Page 8
(This page has no text content)
Page 9
(This page has no text content)
Page 10
(This page has no text content)
Page 11
(This page has no text content)
Page 12
(This page has no text content)
Page 13
(This page has no text content)
Page 14
xiii About the Author Mikael Olsson is a professional web entrepreneur, programmer, and author. He works for an R&D company in Finland where he specializes in software development. In his spare time, he writes books and creates websites 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.
Page 15
xv About the Technical Reviewer Marc Gregoire is a software engineer from Belgium. He graduated from the University of Leuven, Belgium, with a degree in “Burgerlijk ingenieur in de computerwetenschappen” (equivalent to a master of science degree in computer engineering). The year after, he received the cum laude degree of master in artificial intelligence at the same university. After his studies, Marc started working for a software consultancy company called Ordina Belgium. As a consultant, he worked for Siemens and Nokia Siemens Networks on critical 2G and 3G software running on Solaris for telecom operators. This required working on international teams stretching from South America and the United States to Europe, the Middle East, and Asia. Currently, Marc works for Nikon Metrology on industrial 3D laser scanning software.
Page 16
xvii Introduction The C++ programming language is a general-purpose multiparadigm language created by Bjarne Stroustrup. The development of the language started in 1979 under the name “C with classes.” As the name implies, it was an extension of the C language with the additional concept of classes. Stroustrup wanted to create a better C that combined the power and efficiency of C with high-level abstractions to better manage large development projects. The resulting language was renamed C++ (pronounced “C-plus-plus”) in 1983. As a deliberate design feature, C++ maintains compatibility with C, and so most C code can easily be made to compile in C++. The introduction of C++ became a major milestone in the software industry as a widely successful language for both system and application development. System programming involves software that controls the computer hardware directly, such as drivers, operating systems, and software for embedded microprocessors. These areas remain the core domain of the language, where resources are scarce and come at a premium. C++ is also widely used for writing applications, which run on top of system software, especially high-performance software such as games, databases, and resource-demanding desktop applications. Despite the introduction of many modern, high-level languages in this domain— such as Java, C#, and Python—C++ still holds its own and overall remains one of the most popular and influential programming languages in use today. There are several reasons for the widespread adoption of C++. The foremost reason was the rare combination of high-level and low-level abstractions from the hardware. The low-level efficiency was inherited
Page 17
xviii from C, and the high-level constructs came in part from a simulation language called Simula. This combination makes it possible to write C++ software with the strength of both approaches. Another strong point of the language is that it does not impose a specific programming paradigm on its users. It is designed to give the programmer a lot of freedom by supporting many different programming styles or paradigms, such as procedural, object-oriented, and generic programming. C++ is updated and maintained by the C++ standards committee. In 1998, the first international standard was published, known informally as C++98. The language has since undergone five more revisions with further improvements, including C++03, C++11, C++14, C++17, and most recently C++20, which is the latest ISO standard for the C++ programming language released in 2020. InTroduCTIon
Page 18
1© Mikael Olsson 2020 M. Olsson, C++20 Quick Syntax Reference, https://doi.org/10.1007/978-1-4842-5995-5_1 CHAPTER 1 Hello World 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.1 The C++ compiler that comes with this IDE has good support for the C++17 standard and includes many features of C++20 as of the 2019 version. If you are running the Visual Studio installer on Windows, make sure to select the “Desktop development with C++” workload to enable development in C++. Visual Studio is available on Windows and Mac, and there is a lightweight version called Visual Studio Code which can also be run on Linux. 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. 1 http://visualstudio.microsoft.com
Page 19
2 Creating a Project After installing Visual Studio 2019, 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 Create a new project window. From there, select the C++ language from the drop-down list to view only the C++ project templates. Then select the Empty Project template and click the Next button. At the next screen, you can configure the name and location of the project if you want to. When you are finished, click the Create 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 the Source Files folder and choose Add ➤ New Item. From the Add New Item dialog box, choose the C++ File (.cpp) type. 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 latest standard from the drop-down list (std:c++latest). Click OK and the project will now be configured to compile with the latest supported C++20 features. Chapter 1 hello World
Page 20
3 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, are 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 <iostream> 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. This is the standard output stream in C++ which can 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 a statement. Chapter 1 hello World
The above is a preview of the first 20 pages. Register to read the complete e-book.

Recommended for You

Loading recommended books...
Failed to load, please try again later

Tip the Site

Scan the WeChat Pay or Alipay code to tip. No login required.

WeChat Pay
Alipay
Back to List