A Tour of C++ - Phiên Bản Thứ Hai

Chuyên khảo phân tích A tour of c 2nd edition c in depth series, đánh giá các khía cạnh quan trọng, đề xuất hướng nghiên cứu tiếp theo.

Trường đại học

Pearson Education

Chuyên ngành

C++ Programming

Người đăng

Ẩn danh

Thể loại

book

2018

255
2
0

Phí lưu trữ

55 Point

Mục lục chi tiết

Preface

1. CHƯƠNG 1: The Basics

1.1. Introduction

1.2. Programs

1.3. Functions

1.4. Types, Variables, and Arithmetic

1.5. Scope and Lifetime

1.6. Pointers, Arrays, and References

1.7. Mapping to Hardware

1.8. Advice

2. CHƯƠNG 2: User-Defined Types

3. CHƯƠNG 3: Modularity

3.1. Function Arguments and Return Values

3.2. Copy and Move

7. CHƯƠNG 7: Concepts and Generic Programming

7.1. Template Compilation Model

8. CHƯƠNG 8: Library Overview

8.1. Standard-Library Components

8.2. Standard-Library Headers and Namespace

9. CHƯƠNG 9: Strings and Regular Expressions

10. CHƯƠNG 10: Input and Output

10.1. I/O of User-Defined Types

10.2. Use of Iterators

10.3. Range Checking: span

16. CHƯƠNG 16: History and Compatibility

Index

Tóm tắt

I. Hướng Dẫn Chi Tiết Về C Phiên Bản Thứ Hai

C++ là một ngôn ngữ lập trình mạnh mẽ, được sử dụng rộng rãi trong phát triển phần mềm. Phiên bản thứ hai của 'A Tour of C++' của Bjarne Stroustrup cung cấp cái nhìn sâu sắc về ngôn ngữ này. Tài liệu này không chỉ giúp người đọc hiểu rõ hơn về C++ mà còn giới thiệu các tính năng mới trong các phiên bản gần đây như C++11, C++14 và C++17.

1.1. Tổng Quan Về C và Các Phiên Bản

C++ đã trải qua nhiều phiên bản, mỗi phiên bản đều mang lại những cải tiến đáng kể. Từ C++98 đến C++17, ngôn ngữ này đã phát triển để hỗ trợ lập trình hướng đối tượng và lập trình tổng quát.

1.2. Tại Sao Nên Học C Ngày Nay

C++ không chỉ là một ngôn ngữ lập trình cổ điển mà còn là nền tảng cho nhiều ngôn ngữ hiện đại khác. Việc nắm vững C++ giúp lập trình viên có khả năng làm việc với các hệ thống phức tạp và tối ưu hóa hiệu suất.

II. Những Thách Thức Khi Học C Phiên Bản Thứ Hai

Học C++ có thể gặp nhiều khó khăn, đặc biệt là đối với những người mới bắt đầu. Các khái niệm như con trỏ, tham chiếu và quản lý bộ nhớ có thể gây nhầm lẫn. Tuy nhiên, việc hiểu rõ những thách thức này sẽ giúp người học vượt qua và phát triển kỹ năng lập trình của mình.

2.1. Khó Khăn Trong Việc Hiểu Con Trỏ và Tham Chiếu

Con trỏ và tham chiếu là hai khái niệm quan trọng trong C++. Việc sử dụng sai có thể dẫn đến lỗi nghiêm trọng trong chương trình. Cần có thời gian để làm quen và thực hành.

2.2. Quản Lý Bộ Nhớ Trong C

Quản lý bộ nhớ là một trong những thách thức lớn nhất khi lập trình bằng C++. Việc không giải phóng bộ nhớ đúng cách có thể dẫn đến rò rỉ bộ nhớ và làm giảm hiệu suất của ứng dụng.

III. Phương Pháp Học C Hiệu Quả Nhất

Để học C++ hiệu quả, người học cần có phương pháp học tập rõ ràng. Việc kết hợp lý thuyết với thực hành sẽ giúp củng cố kiến thức và kỹ năng lập trình. Dưới đây là một số phương pháp học tập hiệu quả.

3.1. Thực Hành Qua Các Dự Án Nhỏ

Thực hành là cách tốt nhất để học C++. Bắt đầu với các dự án nhỏ giúp người học áp dụng lý thuyết vào thực tế và hiểu rõ hơn về cách hoạt động của ngôn ngữ.

3.2. Sử Dụng Tài Nguyên Học Tập Trực Tuyến

Có nhiều tài nguyên học tập trực tuyến miễn phí và trả phí. Các khóa học, video hướng dẫn và diễn đàn lập trình viên là những nơi tuyệt vời để tìm kiếm thông tin và hỗ trợ.

IV. Ứng Dụng Thực Tiễn Của C Trong Lập Trình

C++ được sử dụng rộng rãi trong nhiều lĩnh vực khác nhau, từ phát triển phần mềm đến lập trình hệ thống. Việc hiểu rõ ứng dụng thực tiễn của C++ sẽ giúp người học có cái nhìn tổng quan hơn về ngôn ngữ này.

4.1. C Trong Phát Triển Phần Mềm

C++ là lựa chọn hàng đầu cho phát triển phần mềm nhờ vào hiệu suất và khả năng kiểm soát tài nguyên. Nhiều ứng dụng lớn như hệ điều hành và trình biên dịch được viết bằng C++.

4.2. C Trong Lập Trình Hệ Thống

C++ thường được sử dụng trong lập trình hệ thống, nơi yêu cầu hiệu suất cao và khả năng tương tác với phần cứng. Các ứng dụng như driver và hệ thống nhúng thường sử dụng C++.

V. Kết Luận Về C Phiên Bản Thứ Hai

C++ là một ngôn ngữ lập trình mạnh mẽ và linh hoạt, phù hợp cho cả lập trình viên mới và chuyên nghiệp. Việc nắm vững C++ không chỉ giúp cải thiện kỹ năng lập trình mà còn mở ra nhiều cơ hội nghề nghiệp.

5.1. Tương Lai Của C

C++ tiếp tục phát triển với các phiên bản mới, mang lại nhiều tính năng hiện đại. Việc theo kịp các xu hướng mới trong C++ sẽ giúp lập trình viên duy trì tính cạnh tranh trong ngành.

5.2. Lời Khuyên Cho Người Mới Bắt Đầu

Người mới bắt đầu nên kiên nhẫn và thực hành thường xuyên. Tham gia cộng đồng lập trình viên và tìm kiếm sự hỗ trợ từ những người có kinh nghiệm sẽ giúp quá trình học tập trở nên dễ dàng hơn.

Tóm tắt và mô tả trên trang này được tạo với sự hỗ trợ của AI. Nếu bạn thấy nội dung không chính xác hoặc có vấn đề, vui lòng Báo lỗi nội dung.

12/07/2025
A tour of c 2nd edition c in depth series

Trích đoạn nội dung tài liệu

A Tour of C++ Second Edition C++ In-Depth Series Bjarne Stroustrup, Series Editor Visit informit.com/series/indepth for a complete list of available publications. T he C++ In-Depth Series is a collection of concise and focused books that provide real-world programmers with reliable information about the C++ programming language. Selected by the designer and original implementor of C++, Bjarne Stroustrup, and written by carefully chosen experts in the field, each book in this series presents either a single topic, at a technical level appropriate to that topic, or a fast-paced overview, for a quick understanding of broader language features. In either case, the series’ practical approach is designed to lift professionals (and aspiring professionals) to the next level of programming skill or knowledge.

Make sure to connect with us! informit.com/socialconnect A Tour of C++ Second Edition Bjarne Stroustrup Boston • Columbus • New York • San Francisco • Amsterdam • Cape Town Dubai • London • Madrid • Milan • Munich • Paris • Montreal • Toronto • Delhi • Mexico City São Paulo • Sydney • Hong Kong • Seoul • Singapore • Taipei • Tokyo 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 author 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.

For information about buying this title in bulk quantities, or for special sales opportunities (which may include electronic versions; custom cover designs; and content particular to your business, training goals, marketing focus, or branding inter- ests), please contact our corporate sales department at corpsales@pearsoned. For government sales inquiries, please contact governmentsales@pearsoned. For questions about sales outside the U., please contact intlcs@pearson. Visit us on the Web: informit.com/aw Library of Congress Control Number: 2018941627 Copyright © 2018 by 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, mechani- cal, 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. This book was typeset in Times and Helvetica by the author.

ISBN-13: 978-0-13-499783-4 ISBN-10: 0-13-499783-2 Third printing, March 2019 3 19 Contents Preface xi 1 The Basics 1 1.4 Types, Variables, and Arithmetic .5 Scope and Lifetime .7 Pointers, Arrays, and References .9 Mapping to Hardware. 18 2 User-Defined Types 21 2. 27 vi Contents 3 Modularity 29 3.6 Function Arguments and Return Values .2 Copy and Move. 92 7 Concepts and Generic Programming 93 7.5 Template Compilation Model.

104 vii 8 Library Overview 107 8.2 Standard-Library Components .3 Standard-Library Headers and Namespace. 110 9 Strings and Regular Expressions 111 9. 122 10 Input and Output 123 10.5 I/O of User-Defined Types .2 Use of Iterators .3 Range Checking: span .2 Tasks and threads .6 Waiting for Events. 205 ix 16 History and Compatibility 207 16.

225 Index 227 This page intentionally left blank Preface When you wish to instruct, be brief. – Cicero C++ feels like a new language. That is, I can express my ideas more clearly, more simply, and more directly today than I could in C++98. Furthermore, the resulting programs are better checked by the compiler and run faster.

This book gives an overview of C++ as defined by C++17, the current ISO C++ standard, and implemented by the major C++ suppliers. In addition, it mentions concepts and modules, as defined in ISO Technical Specifications and in current use, but not scheduled for inclusion into the standard until C++20. Like other modern languages, C++ is large and there are a large number of libraries needed for effective use. This thin book aims to give an experienced programmer an idea of what constitutes modern C++.

It covers most major language features and the major standard-library components. This book can be read in just a few hours but, obviously, there is much more to writing good C++ than can be learned in a day. However, the aim here is not mastery, but to give an overview, to give key examples, and to help a programmer get started. The assumption is that you have programmed before.

If not, please consider reading a text- book, such as Programming: Principles and Practice Using C++ (Second edition) [Strous- trup,2014], before continuing here. Even if you have programmed before, the language you used or the applications you wrote may be very different from the style of C++ presented here. Think of a sightseeing tour of a city, such as Copenhagen or New York. In just a few hours, you are given a quick peek at the major attractions, told a few background stories, and given some sug- gestions about what to do next.

You do not know the city after such a tour. You do not understand all you have seen and heard. You do not know how to navigate the formal and informal rules that govern life in the city. To really know a city, you have to live in it, often for years.

However, with a bit of luck, you will have gained a bit of an overview, a notion of what is special about the city, and ideas of what might be of interest to you. After the tour, the real exploration can begin. xii Preface This tour presents the major C++ language features as they support programming styles, such as object-oriented and generic programming. It does not attempt to provide a detailed, reference-man- ual, feature-by-feature view of the language.

In the best textbook tradition, I try to explain a feature before I use it, but that is not always possible and not everybody reads the text strictly sequentially. So, the reader is encouraged to use the cross references and the index. Similarly, this tour presents the standard libraries in terms of examples, rather than exhaustively. It does not describe libraries beyond those defined by the ISO standard.

The reader can search out supporting material as needed. [Stroustrup,2013] and [Stroustrup,2014] are examples of such material, but there is an enormous amount of material (of varying quality) available on the Web, e. For example, when I mention a standard-library function or class, its defini- tion can easily be looked up, and by examining its documentation, many related facilities can be found. This tour presents C++ as an integrated whole, rather than as a layer cake.

Consequently, it does not identify language features as present in C, part of C++98, or new in C++11, C++14, or C++17. Such information can be found in Chapter 16 (History and Compatibility). I focus on fun- damentals and try to be brief, but I have not completely resisted the temptation to overrepresent novel features. This also seems to satisfy the curiosity of many readers who already know some older version of C++.

A programming language reference manual or standard simply states what can be done, but pro- grammers are often more interested in learning how to use the language well. This aspect is partly addressed in the selection of topics covered, partly in the text, and specifically in the advice sec- tions. More advice about what constitutes good modern C++ can be found in the C++ Core Guide- lines [Stroustrup,2015]. The core guidelines can be a good source for further exploration of the ideas presented in this book.

You may note a remarkable similarity of the advice formulation and even the numbering of advice between the Core Guidelines and this book. One reason is that the first edition of A Tour of C++ was a major source of the initial Core Guidelines. Acknowledgments Some of the material presented here is borrowed from TC++PL4 [Stroustrup,2013], so thanks to all who helped completing that book. Thanks to all who help complete and correct the first edition of ‘‘A Tour of C++.’’ Thanks to Morgan Stanley for giving me time to write this second edition.

Thanks to the Co- lumbia University Spring 2018 ‘‘Design Using C++’’ class for finding many a typo and bug in an early draft of this book and for making many constructive suggestions. Thanks to Paul Anderson, Chuck Allison, Peter Gottschling, William Mon, Charles Wilson, and Sergey Zubkov for reviewing the book and suggesting many improvements. Manhattan, New York Bjarne Stroustrup 1 The Basics The first thing we do, let’s kill all the language lawyers. – Henry VI, Part II • Introduction • Programs Hello, World! • Functions • Types, Variables, and Arithmetic Arithmetic; Initialization • Scope and Lifetime • Constants • Pointers, Arrays, and References The Null Pointer • Tests • Mapping to Hardware Assignment; Initialization • Advice 1.1 Introduction This chapter informally presents the notation of C++, C++’s model of memory and computation, and the basic mechanisms for organizing code into a program.

These are the language facilities supporting the styles most often seen in C and sometimes called procedural programming. 2 The Basics Chapter 1 1.2 Programs C++ is a compiled language. For a program to run, its source text has to be processed by a com- piler, producing object files, which are combined by a linker yielding an executable program. A C++ program typically consists of many source code files (usually simply called source files).

source file 1 compile object file 1 link executable file source file 2 compile object file 2 An executable program is created for a specific hardware/system combination; it is not portable, say, from a Mac to a Windows PC. When we talk about portability of C++ programs, we usually mean portability of source code; that is, the source code can be successfully compiled and run on a variety of systems. The ISO C++ standard defines two kinds of entities: • Core language features, such as built-in types (e., char and int) and loops (e., for-state- ments and while-statements) • Standard-library components, such as containers (e., vector and map) and I/O operations (e., << and getline()) The standard-library components are perfectly ordinary C++ code provided by every C++ imple- mentation. That is, the C++ standard library can be implemented in C++ itself and is (with very minor uses of machine code for things such as thread context switching).

This implies that C++ is sufficiently expressive and efficient for the most demanding systems programming tasks. C++ is a statically typed language. That is, the type of every entity (e., object, value, name, and expression) must be known to the compiler at its point of use. The type of an object determines the set of operations applicable to it.1 Hello, World! The minimal C++ program is int main() { } // the minimal C++ program This defines a function called main, which takes no arguments and does nothing.

Curly braces, { }, express grouping in C++. Here, they indicate the start and end of the function body. The double slash, //, begins a comment that extends to the end of the line. A comment is for the human reader; the compiler ignores comments.

Every C++ program must have exactly one global function named main(). The program starts by executing that function. The int integer value returned by main(), if any, is the program’s return value to ‘‘the system.’’ If no value is returned, the system will receive a value indicating successful completion. A nonzero value from main() indicates failure.

Not every operating system and execu- tion environment make use of that return value: Linux/Unix-based environments do, but Windows- based environments rarely do.1 Hello, World! 3 Typically, a program produces some output.

Nội dung được bảo vệ bản quyền — Tải xuống đầy đủ