CITATION

Schildt, Herbert. Herb Schildt's C++ Programming Cookbook. US: McGraw-Hill Osborne Media, 2008.

Herb Schildt's C++ Programming Cookbook

Published:  April 2008

eISBN: 9780071643856 0071643850 | ISBN: 9780071488600
  • Contents
  • Preface
  • 1 Overview
  • What's Inside
  • How the Recipes Are Organized
  • A Few Words of Caution
  • C++ Experience Required
  • What Version of C++?
  • Two Coding Conventions
  • Returning a Value from main( )
  • Using Namespace std?
  • 2 String Handling
  • Overview of Null-Terminated Strings
  • Overview of the string Class
  • String Exceptions
  • Perform Basic Operations on Null-Terminated Strings
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Search a Null-Terminated String
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Reverse a Null-Terminated String
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Ignore Case Differences When Comparing Null-Terminated Strings
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Create a Search-and-Replace Function for Null-Terminated Strings
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Categorize Characters Within a Null-Terminated String
  • Step-by-Step
  • Discussion
  • Example
  • Bonus Example: Word Count
  • Options and Alternatives
  • Tokenize a Null-Terminated String
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Perform Basic Operations on string Objects
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Search a string Object
  • Step-by-Step
  • Discussion
  • Example
  • Bonus Example: A Tokenizer Class for string Objects
  • Options and Alternatives
  • Create a Search-and-Replace Function for string Objects
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Operate on string Objects Through Iterators
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Create Case-Insensitive Search and Search-and-Replace Functions for string Objects
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Convert a string Object into a Null-Terminated String
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Implement Subtraction for string Objects
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • 3 Working with STL Containers
  • STL Overview
  • Containers
  • Algorithms
  • Iterators
  • Allocators
  • Function Objects
  • Adaptors
  • Predicates
  • Binders and Negators
  • The Container Classes
  • Common Functionality
  • Performance Issues
  • Basic Sequence Container Techniques
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Use vector
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Use deque
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Use list
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Use the Sequence Container Adaptors: stack, queue, and priority_queue
  • Step-by-Step
  • Discussion
  • Example
  • Bonus Example: Use stack to Create a Four-Function Calculator
  • Options and Alternatives
  • Store User-Defined Objects in a Container
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Basic Associative Container Techniques
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Use map
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Use multimap
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Use set and multiset
  • Step-by-Step
  • Discussion
  • Example
  • Bonus Example: Use multiset to Store Objects with Duplicate Keys
  • Options and Alternatives
  • 4 Algorithms, Function Objects, and Other STL Components
  • Algorithm Overview
  • Why Algorithms?
  • Algorithms Are Template Functions
  • The Algorithm Categories
  • Function Object Overview
  • Binders and Negators Overview
  • Sort a Container
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Find an Element in a Container
  • Step-by-Step
  • Discussion
  • Example
  • Bonus Example: Extract Sentences from a Vector of Characters
  • Options and Alternatives
  • Use search( ) to Find a Matching Sequence
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Reverse, Rotate, and Shuffle a Sequence
  • Step-by-Step
  • Discussion
  • Example
  • Bonus Example: Use Reverse Iterators to Perform a Right-Rotate
  • Options and Alternatives
  • Cycle Through a Container with for_each( )
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Use transform( ) to Change a Sequence
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Perform Set Operations
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Permute a Sequence
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Copy a Sequence from One Container to Another
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Replace and Remove Elements in a Container
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Merge Two Sorted Sequences
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Create and Manage a Heap
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Create an Algorithm
  • Step-by-Step
  • Discussion
  • Example
  • Bonus Example: Use a Predicate with a Custom Algorithm
  • Options and Alternatives
  • Use a Built-In Function Object
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Create a Custom Function Object
  • Step-by-Step
  • Discussion
  • Example
  • Bonus Example: Use a Function Object to Maintain State Information
  • Options and Alternatives
  • Use a Binder
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Use a Negator
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Use the Pointer-to-Function Adaptor
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Use the Stream Iterators
  • Step-by-Step
  • Discussion
  • Example
  • Bonus Example: Create an STL-Based File Filter
  • Options and Alternatives
  • Use the Insert Iterator Adaptors
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • 5 Working with I/O
  • I/O Overview
  • C++ Streams
  • The C++ Stream Classes
  • The Stream Class Specializations
  • C++'s Predefined Streams
  • The Format Flags
  • The I/O Manipulators
  • Checking for Errors
  • Opening and Closing a File
  • Write Formatted Data to a Text File
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Read Formatted Data from a Text File
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Write Unformatted Binary Data to a File
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Read Unformatted Binary Data from a File
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Use get( ) and getline( ) to Read from a File
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Read from and Write to a File
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Detecting EOF
  • Step-by-Step
  • Discussion
  • Example
  • Bonus Example: A Simple File-Comparison Utility
  • Options and Alternatives
  • Use Exceptions to Detect and Handle I/O Errors
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Use Random-Access File I/O
  • Step-by-Step
  • Discussion
  • Example
  • Bonus Example: Use Random-Access I/O to Access Fixed-Size Records
  • Options and Alternatives
  • Look Ahead in a File
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Use the String Streams
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Create Custom Inserters and Extractors
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Create a Parameterless Manipulator
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Create a Parameterized Manipulator
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Obtain or Set a Stream's Locale
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Use the C-Based File System
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Rename and Remove a File
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • 6 Formatting Data
  • Formatting Overview
  • The Format Flags
  • The Field Width, Precision, and Fill Character
  • Format-Related Stream Member Functions
  • The I/O Manipulators
  • Format Data Using the Localization Library
  • The printf( ) Family of Functions
  • The strftime( ) Function
  • Facet Overview
  • Access the Format Flags via Stream Member Functions
  • Step-by-Step
  • Discussion
  • Example
  • Bonus Example: Display the Format Flag Settings
  • Options and Alternatives
  • Display Numeric Values in Various Formats
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Set the Precision
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Set the Field Width and Fill Character
  • Step-by-Step
  • Discussion
  • Example
  • Bonus Example: Line Up Columns of Numbers
  • Options and Alternatives
  • Justify Output
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Use I/O Manipulators to Format Data
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Format Numeric Values for a Locale
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Format Monetary Values Using the money_put Facet
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Use the moneypunct and numpunct Facets
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Format Time and Date Using the time_put Facet
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Format Data into a String
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Format Time and Date Using strftime( )
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Use printf( ) to Format Data
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • 7 Potpourri
  • Operator Overloading Basic Techniques
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Overload the Function Call Operator ( )
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Overload the Subscripting Operator [ ]
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Overload the → Operator
  • Step-by-Step
  • Discussion
  • Example
  • Bonus Example: A Simple Safe Pointer Class
  • Options and Alternatives
  • Overload new and delete
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Overload the Increment and Decrement Operators
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Create a Conversion Function
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Create a Copy Constructor
  • Step-by-Step
  • Discussion
  • Example
  • Bonus Example: A Safe Array that Uses Dynamic Allocation
  • Options and Alternatives
  • Determine an Object's Type at Runtime
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Use Complex Numbers
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Use auto_ptr
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Create an Explicit Constructor
  • Step-by-Step
  • Discussion
  • Example
  • Options and Alternatives
  • Index