Home > Store

C++ for the Impatient

Register your product to gain access to bonus material or receive a coupon.

C++ for the Impatient

eBook

  • Your Price: $46.39
  • List Price: $57.99
  • Includes EPUB and PDF
  • About eBook Formats
  • This eBook includes the following formats, accessible from your Account page after purchase:

    ePub EPUB The open industry format known for its reflowable content and usability on supported mobile devices.

    Adobe Reader PDF The popular standard, used most often with the free Acrobat® Reader® software.

    This eBook requires no passwords or activation to read. We customize your eBook by discreetly watermarking it with your name, making it uniquely yours.

Description

  • Copyright 2013
  • Dimensions: 7-3/8" x 9-1/8"
  • Edition: 1st
  • eBook
  • ISBN-10: 0-13-325709-6
  • ISBN-13: 978-0-13-325709-0

A Ready Reference for C++

C++ for the Impatient offers both the quickest way for busy programmers to learn the latest features of the C++ language and a handy resource for quickly finding answers to specific language questions. Designed to give you the most accurate and up-to-date information you require fast and to the point, this book is also an essential guide to the new C++11 standard, including advanced uses of the C++ standard library. 


Features include

·      Concise descriptions of nearly every function, object, and operator in the C++ core language and standard library, with clear, well-chosen examples for each of them

·      Information provided “at a glance” through syntax displays, tables, and summaries of important functions

·      Content organized for quick look-up of needed information

·      Simple explanations of advanced concepts, using helpful illustrations

·      Complete program examples that are both useful and intriguing, including puzzles, games, and challenging exercises



C++11 features, all covered in the book, include:

·      Lambdas

·      rvalue references

·      Regular-expression library

·      Randomization library

·      Hash-table containers

·      Smart pointers


C++ for the Impatient is an ideal resource for anyone who needs to come up to speed quickly on C++11. Whether or not it’s your first C++ book, it will be one you come back to often for reliable answers.



Sample Content

Table of Contents

Preface xix

Acknowledgments xxvii

About the Author xxix

Chapter 1: C++ Fundamentals 1

1.1 Elements of a C++ Program 1

1.2 Dealing with “Flashing Console” 4

1.3 Working with Microsoft Visual Studio 5

1.4 Doing More with C++ 6

1.5 Adding Simple Variable Declarations 7

1.6 Introduction to C++ Control Structures 10

1.6.1 Making Decisions with “if” 11

1.6.2 Looping with “while” 13

1.7 General Structure of a C++ Program 14

1.8 More about Namespaces 15

1.9 Some Comments about Comments 17

1.9.1 C++ Comments (Line Comments) 17

1.9.2 C-Language-Style Comments 17

1.10 Sample App: Adding Machine 19

Exercises 20

1.11 Sample App: Calculating Phi 20

Exercises 23

Chapter 2: Data 25

2.1 Declaring Simple Variables 25

2.2 Primitive Data Types 27

2.3 Symbolic Names (“Symbols”) 30

2.4 Numeric Literals 31

2.5 Mixing Numeric Types 33

2.5.1 Integer versus Floating Point 34

2.5.2 bool versus Integer Types 34

2.5.3 Signed versus Unsigned Integers 35

2.6 String and Character Literals 39

2.6.1 Single-Quoted Characters 39

2.6.2 Double-Quoted Strings 40

2.6.3 Special Characters (Escape Sequences) 41

2.6.4 Wide-Character Strings 45

2.6.5 Raw String Literals (C++11) 46

2.7 Data Declarations: The Complete Syntax 46

2.8 Enumerated Types 50

2.9 Special Declarations (typedef, auto, decltype) 52

2.9.1 The typedef Keyword 52

2.9.2 The auto and decltype Keywords (C++11) 53

2.10 Sample App: Type Promotion 54

Exercises 55

Chapter 3: Operators 57

3.1 Precedence, Associativity, and Lvalues 57

3.2 Concise Summary of Operators 59

3.3 Operators in Detail 62

3.4 The Great Controversy: Postfix or Prefix? 77

3.5 Bitwise Operators in Detail 78

3.6 Cast Operators 82

Exercises 90

Chapter 4: Control Structures 91

4.1 Concise Summary of C++ Statements 91

4.2 Null Statements (;) and Expression Statements 93

4.3 Compound Statements 94

4.4 if and if-else Statements 96

4.5 while and do-while Statements 98

4.6 for Statements 99

4.7 Range-based for Statements (C++11) 101

4.8 switch Statements 103

4.9 Jump Statements (break, continue, goto) 104

4.10 Exception Handling (try, catch) 106

4.11 Sample App: Guess-the-Number Game 111

Exercises 113

4.12 Sample App: Computer Guesses the Number 113

Exercises 115

Chapter 5: Functions 117

5.1 Overview of Traditional (Named) Functions 117

5.2 Local and Global Variables 122

5.3 Complete Function Declaration Syntax 124

5.4 Function Overloading 126

5.5 Arguments with Default Values 128

5.6 Variable-Length Argument Lists 129

5.7 Lambda, or Anonymous, Functions (C++11) 131

5.8 constexpr Functions (C++11) 141

5.9 Sample App: Odds at Dice 142

Exercises 145

Chapter 6: Pointers, Arrays, and References 147

6.1 References 147

6.2 Arrays 152

6.3 Pointers 159

6.4 Complex Declarations Involving Pointers 175

6.5 Passing and Returning Function Pointers 178

6.6 Smart Pointers (C++11) 180

6.7 Sample App: Sieve of Eratosthenes 186

Exercises 188

Chapter 7: Classes and Objects 189

7.1 Overview: Structures, Unions, and Classes 189

7.2 Basic Class Declaration Syntax 191

7.3 Constructors 205

7.4 Destructors 216

7.5 The Hidden “this” Pointer 217

7.6 Operator Functions (Op Overloading) 218

7.7 Deriving Classes (Subclassing) 229

7.8 Bit Fields 240

7.9 Unions 242

7.10 Sample App: Packed Boolean 245

Exercises 248

Chapter 8: Preprocessor Directives 249

8.1 General Syntax of Preprocessor Directives 249

8.2 Summary of Preprocessor Directives 250

8.3 Using Directives to Solve Specific Problems 254

8.3.1 Creating Meaningful Symbols with #define 254

8.4 Preprocessor Operators 259

8.5 Predefined Macros 260

8.6 Creating Project Header Files 263

Chapter 9: Creating and Using Templates 265

9.1 Templates: Syntax and Overview 265

9.2 Function Templates 267

9.3 Class Templates 272

9.4 Class Templates with Member Functions 276

9.4.1 Class Templates with Inline Member Functions 276

9.4.2 Class Templates with Separate Function Definitions 276

9.5 Using Integer Template Parameters 278

9.6 Template Specialization 279

9.7 Variadic Templates (C++11) 281

9.8 Sample App: Type Promotion, v 2 288

Exercises 289

Chapter 10: C-String Library Functions 291

10.1 Overview of the C-String Format 291

10.2 Input and Output with C-Strings 293

10.3 C-String Functions 294

10.4 String Tokenizing with strtok 300

10.5 Individual-Character Functions 301

10.6 Memory-Block Functions (memcpy, and so on) 304

10.7 Wide-Character Functions (wstrcpy, and so on) 306

Chapter 11: C I/O Library Functions 309

11.1 Overview of C Library I/O 309

11.2 Console I/O Functions 310

11.3 Print/Scan Formats 313

11.4 Input and Output to Strings 321

11.5 File I/O 321

Chapter 12: Math, Time, and Other Library Functions 333

12.1 Trigonometric Functions 333

12.2 Other Math Functions 336

12.3 The C Date and Time Library 339

12.4 String-to-Number Conversions 347

12.5 Memory-Allocation Functions 348

12.6 Standard C Randomization Functions 350

12.7 Searching and Sorting Functions 351

12.8 Other Standard C Library Functions 355

12.9 Sample App: Idiot Savant 358

Exercises 359

Chapter 13: C++ I/O Stream Classes 361

13.1 The Basics of C++ I/O Streams 361

13.2 Reading a Line of Input with getline 364

13.3 The C++ Stream-Class Hierarchy 366

13.4 Stream Objects: Manipulators and Flags 368

13.5 Stream Member Functions (General Purpose) 379

13.6 File Stream Operations 385

13.7 Reading and Writing String Streams 395

13.8 Overloading Shift Operators for Your Classes 398

13.9 Sample App: Text File Reader 400

Exercises 401

Chapter 14: The C++ STL String Class 403

14.1 Overview of the String Class 403

14.2 String Class Constructors 405

14.3 String Class Operators 406

14.4 Concise Summary of Member Functions 410

14.5 Member Functions in Detail 410

14.6 String Class Iterators 424

14.7 Wide-Character String Class (basic_string) 430

Chapter 15: Introduction to STL (vector, deque) 431

15.1 A Tour of the Container Templates 431

15.2 Introduction to Iterators 433

15.3 The vector Template 434

15.4 The deque Template 447

15.5 The bitset Template 458

15.5.1 bitset Constructors 459

15.6 Sample App: Alpha File Organizer 461

Exercises 463

Chapter 16: STL Sequence Containers (List) 465

16.1 Sorting Elements (Strict Weak Ordering) 465

16.2 The list Template 466

16.2.3 Concise Summary of list Functions 471

16.2.4 List Member Functions in Detail 472

16.3 The stack Template 481

16.4 The queue Template 484

16.5 The priority_queue Template 487

16.6 Sample App: Find the Median 491

Exercises 493

Chapter 17: STL Associated Containers (map, set) 495

17.1 The pair Template 495

17.2 The map Template 497

17.3 The set Template 518

17.4 The multimap Template 529

17.5 The multiset Template 532

17.6 Unordered Containers (C++11) 534

17.7 Sample App: Guess-the-Word Game 543

Exercises 545

Chapter 18: STL Algorithms 547

18.1 STL Algorithms: General Concepts 547

18.2 Using Lambda Functions (C++11) 550

18.3 Algorithms and Iterators 551

18.4 Insert Iterators 553

18.5 Sample App: Finding the Median 555

18.6 Concise Summaries of Algorithms 556

18.7 Detailed Descriptions of Algorithms 564

Chapter 19: C++11 Randomization Library 599

19.1 Issues in Randomization 599

19.2 A Better Randomization Scheme 601

19.3 Common Engines 604

19.4 Common Distributions 605

19.5 Operations on Engines 608

19.6 Operations on Distributions 609

19.7 Sample App: Dice Game 610

Exercises 612

Chapter 20: C++11 Regular-Expression Library 613

20.1 Overview of C++11 Regular Expressions 613

20.2 Dealing with Escape Sequences (Ä) 616

20.3 Constructing a RegEx String 618

20.4 Matching and Searching Functions 624

20.5 “Find All,” or Iterative, Searches 626

20.6 Replacing Text 628

20.7 String Tokenizing 630

20.8 Catching RegEx Exceptions 631

20.9 Sample App: RPN Calculator 632

Exercises 635

Appendix A: A Painless Introduction to Rvalue References (C++11) 637

A.1 The Trouble with Copying 637

A.2 Move Semantics: C++11 to the Rescue! 640

A.3 Rvalue Refs in a User’s String Class 642

A.4 Verifying Runtime-Performance Improvement 645

A.5 Rvalues and Contained Objects 646

A.6 References Reconsidered: Rvalues and Lvalues 646


Appendix B: Summary of New Features in C++11 649

B.1 Improvements in Object Construction 649

B.2 Other Core-Language Enhancements 650

B.3 Other New Keywords 651

B.4 Extensions to the Standard Library 652


Appendix C: ASCII Codes 655

Index 659

Updates

Submit Errata

More Information

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020