C++ Cookbook - Helion
ISBN: 978-14-493-6656-8
stron: 594, Format: ebook
Data wydania: 2005-11-08
Księgarnia: Helion
Cena książki: 152,15 zł (poprzednio: 176,92 zł)
Oszczędzasz: 14% (-24,77 zł)
Despite its highly adaptable and flexible nature, C++ is also one of the more complex programming languages to learn. Once mastered, however, it can help you organize and process information with amazing efficiency and quickness.
The C++ Cookbook will make your path to mastery much shorter. This practical, problem-solving guide is ideal if you're an engineer, programmer, or researcher writing an application for one of the legions of platforms on which C++ runs. The algorithms provided in C++ Cookbook will jump-start your development by giving you some basic building blocks that you don't have to develop on your own.
Less a tutorial than a problem-solver, the book addresses many of the most common problems you're likely encounter--whether you've been programming in C++ for years or you're relatively new to the language. Here are just some of the time-consuming tasks this book contains practical solutions for:
- Reading the contents of a directory
- Creating a singleton class
- Date and time parsing/arithmetic
- String and text manipulation
- Working with files
- Parsing XML
- Using the standard containers
Typical of O'Reilly's "Cookbook" series, C++ Cookbook is written in a straightforward format, featuring recipes that contain problem statements and code solutions, and apply not to hypothetical situations, but those that you're likely to encounter. A detailed explanation then follows each recipe in order to show you how and why the solution works. This question-solution-discussion format is a proven teaching method, as any fan of the "Cookbook" series can attest to. This book will move quickly to the top of your list of essential C++ references.
Spis treści
C++ Cookbook eBook -- spis treści
- C++ Cookbook
- A Note Regarding Supplemental Files
- Preface
- About the Examples
- Conventions Used in This Book
- Using Code Examples
- Comments and Questions
- Safari Enabled
- Acknowledgments
- From D. Ryan Stephens
- From Christopher Diggins
- From Jonathan Turkanis
- 1. Building C++ Applications
- Introduction to Building
- Basic Terminology
- IDEs and Build Systems
- Toolset Overview
- The GNU Compiler Collection (GCC)
- Visual C++
- Intel
- Metrowerks
- Borland
- Comeau
- Digital Mars
- IDE Overview
- Visual C++
- CodeWarrior
- C++Builder
- Dev-C++
- John, Paul, George, and Ringo
- 1.1. Obtaining and Installing GCC
- Problem
- Solution
- Windows
- Unix
- Discussion
- See Also
- 1.2. Building a Simple Hello, World Application from the Command Line
- Problem
- Solution
- Discussion
- See Also
- 1.3. Building a Static Library from the Command Line
- Problem
- Solution
- Discussion
- See Also
- 1.4. Building a Dynamic Library from the Command Line
- Problem
- Solution
- Discussion
- Symbol visibility
- Passing libraries to the linker
- Import libraries and module definition files
- Exporting symbols from a DLL
- Importing symbols from a DLL
- Building DLLs with GCC
- GCC 4.0s -fvisibility option
- Symbol Visibility with Metrowerks for Mac OS X
- Command-line options
- See Also
- 1.5. Building a Complex Application from the Command Line
- Problem
- Solution
- Discussion
- Searching for included headers
- Passing libraries to the linker
- Running your application
- See Also
- 1.6. Installing Boost.Build
- Problem
- Solution
- Discussion
- 1.7. Building a Simple Hello, World Application Using Boost.Build
- Problem
- Solution
- Discussion
- See Also
- 1.8. Building a Static Library Using Boost.Build
- Problem
- Solution
- Discussion
- See Also
- 1.9. Building a Dynamic Library Using Boost.Build
- Problem
- Solution
- Discussion
- See Also
- 1.10. Building a Complex application Using Boost.Build
- Problem
- Solution
- Discussion
- Library targets
- Installation
- Project organization
- Library targets
- See Also
- 1.11. Building a Static Library with an IDE
- Problem
- Solution
- Discussion
- CodeWarrior
- C++Builder
- Dev-C++
- See Also
- 1.12. Building a Dynamic Library with an IDE
- Problem
- Solution
- Discussion
- CodeWarrior
- C++Builder
- Dev-C++
- See Also
- 1.13. Building a Complex Application with an IDE
- Problem
- Solution
- Discussion
- CodeWarrior
- C++Builder
- Dev-C++
- See Also
- 1.14. Obtaining GNU make
- Problem
- Solution
- Windows
- Unix
- Discussion
- See Also
- 1.15. Building A Simple Hello, World Application with GNU make
- Problem
- Solution
- Discussion
- Make variables
- Implicit Rules
- Customization points
- VPATH and the vpath directive
- See Also
- 1.16. Building a Static Library with GNU Make
- Problem
- Solution
- Discussion
- See Also
- 1.17. Building a Dynamic Library with GNU Make
- Problem
- Solution
- Discussion
- See Also
- 1.18. Building a Complex Application with GNU make
- Problem
- Solution
- Discussion
- See Also
- 1.19. Defining a Macro
- Problem
- Solution
- Discussion
- See Also
- 1.20. Specifying a Command-Line Option from Your IDE
- Problem
- Solution
- Discussion
- 1.21. Producing a Debug Build
- Problem
- Solution
- Discussion
- See Also
- 1.22. Producing a Release Build
- Problem
- Solution
- Discussion
- See Also
- 1.23. Specifying a Runtime Library Variant
- Problem
- Solution
- Discussion
- See Also
- 1.24. Enforcing Strict Conformance to the C++ Standard
- Problem
- Solution
- Discussion
- See Also
- 1.25. Causing a Source File to Be Linked Automatically Against a Specified Library
- Problem
- Solution
- Discussion
- See Also
- 1.26. Using Exported Templates
- Problem
- Solution
- Discussion
- See Also
- Introduction to Building
- 2. Code Organization
- Introduction
- 2.1. Making Sure a Header File Gets Included Only Once
- Problem
- Solution
- Discussion
- 2.2. Ensuring You Have Only One Instance of a Variable Across Multiple Source Files
- Problem
- Solution
- Discussion
- 2.3. Reducing #includes with Forward Class Declarations
- Problem
- Solution
- Discussion
- 2.4. Preventing Name Collisions with Namespaces
- Problem
- Solution
- Discussion
- 2.5. Including an Inline File
- Problem
- Solution
- 3. Numbers
- Introduction
- 3.1. Converting a String to a Numeric Type
- Problem
- Solution
- Discussion
- See Also
- 3.2. Converting Numbers to Strings
- Problem
- Solution
- Discussion
- See Also
- 3.3. Testing Whether a String Contains a Valid Number
- Problem
- Solution
- Discussion
- See Also
- 3.4. Comparing Floating-Point Numbers with Bounded Accuracy
- Problem
- Solution
- Discussion
- 3.5. Parsing a String Containing a Number in Scientific Notation
- Problem
- Solution
- Discussion
- See Also
- 3.6. Converting Between Numeric Types
- Problem
- Solution
- Discussion
- See Also
- 3.7. Getting the Minimum and Maximum Values for a Numeric Type
- Problem
- Solution
- Discussion
- 4. Strings and Text
- Introduction
- 4.1. Padding a String
- Problem
- Solution
- Discussion
- 4.2. Trimming a String
- Problem
- Solution
- Discussion
- 4.3. Storing Strings in a Sequence
- Problem
- Solution
- Discussion
- 4.4. Getting the Length of a String
- Problem
- Solution
- Discussion
- 4.5. Reversing a String
- Problem
- Solution
- Discussion
- 4.6. Splitting a String
- Problem
- Solution
- Discussion
- 4.7. Tokenizing a String
- Problem
- Solution
- Discussion
- See Also
- 4.8. Joining a Sequence of Strings
- Problem
- Solution
- Discussion
- 4.9. Finding Things in Strings
- Problem
- Solution
- Discussion
- 4.10. Finding the nth Instance of a Substring
- Problem
- Solution
- Discussion
- See Also
- 4.11. Removing a Substring from a String
- Problem
- Solution
- Discussion
- 4.12. Converting a String to Lower- or Uppercase
- Problem
- Solution
- Discussion
- 4.13. Doing a Case-Insensitive String Comparison
- Problem
- Solution
- Discussion
- 4.14. Doing a Case-Insensitive String Search
- Problem
- Solution
- Discussion
- 4.15. Converting Between Tabs and Spaces in a Text File
- Problem
- Solution
- Discussion
- 4.16. Wrapping Lines in a Text File
- Problem
- Solution
- Discussion
- See Also
- 4.17. Counting the Number of Characters, Words, and Lines in a Text File
- Problem
- Solution
- Discussion
- See Also
- 4.18. Counting Instances of Each Word in a Text File
- Problem
- Solution
- Discussion
- See Also
- 4.19. Add Margins to a Text File
- Problem
- Solution
- Discussion
- See Also
- 4.20. Justify a Text File
- Problem
- Solution
- Discussion
- 4.21. Squeeze Whitespace to Single Spaces in a Text File
- Problem
- Solution
- Discussion
- See Also
- 4.22. Autocorrect Text as a Buffer Changes
- Problem
- Solution
- Discussion
- See Also
- 4.23. Reading a Comma-Separated Text File
- Problem
- Solution
- Discussion
- 4.24. Using Regular Expressions to Split a String
- Problem
- Solution
- Discussion
- 5. Dates and Times
- Introduction
- 5.1. Obtaining the Current Date and Time
- Problem
- Solution
- Discussion
- 5.2. Formatting a Date/Time as a String
- Problem
- Solution
- Discussion
- See Also
- 5.3. Performing Date and Time Arithmetic
- Problem
- Solution
- Discussion
- 5.4. Converting Between Time Zones
- Problem
- Solution
- Discussion
- 5.5. Determining a Days Number Within a Given Year
- Problem
- Solution
- Discussion
- 5.6. Defining Constrained Value Types
- Problem
- Solution
- Discussion
- 6. Managing Data with Containers
- Introduction
- 6.1. Using vectors Instead of Arrays
- Problem
- Solution
- Discussion
- See Also
- 6.2. Using vectors Efficiently
- Problem
- Solution
- Discussion
- How vectors work
- Optimizing vector performance
- 6.3. Copying a vector
- Problem
- Solution
- Discussion
- 6.4. Storing Pointers in a vector
- Problem
- Solution
- Discussion
- 6.5. Storing Objects in a list
- Problem
- Solution
- Discussion
- See Also
- 6.6. Mapping strings to Other Things
- Problem
- Solution
- Discussion
- See Also
- 6.7. Using Hashed Containers
- Problem
- Solution
- Discussion
- See Also
- 6.8. Storing Objects in Sorted Order
- Problem
- Solution
- Discussion
- 6.9. Storing Containers in Containers
- Problem
- Solution
- Discussion
- 7. Algorithms
- Introduction
- 7.1. Iterating Through a Container
- Problem
- Solution
- Discussion
- Using iterators
- Iterator categories
- See Also
- 7.2. Removing Objects from a Container
- Problem
- Solution
- Discussion
- See Also
- 7.3. Randomly Shuffling Data
- Problem
- Solution
- Discussion
- 7.4. Comparing Ranges
- Problem
- Solution
- Discussion
- See Also
- 7.5. Merging Data
- Problem
- Solution
- Discussion
- 7.6. Sorting a Range
- Problem
- Solution
- Discussion
- See Also
- 7.7. Partitioning a Range
- Problem
- Solution
- Discussion
- See Also
- 7.8. Performing Set Operations on Sequences
- Problem
- Solution
- Discussion
- See Also
- 7.9. Transforming Elements in a Sequence
- Problem
- Solution
- Discussion
- See Also
- 7.10. Writing Your Own Algorithm
- Problem
- Solution
- Discussion
- See Also
- 7.11. Printing a Range to a Stream
- Problem
- Solution
- Discussion
- 8. Classes
- Introduction
- 8.1. Initializing Class Member Variables
- Problem
- Solution
- Discussion
- See Also
- 8.2. Using a Function to Create Objects (a.k.a. Factory Pattern)
- Problem
- Solution
- Discussion
- See Also
- 8.3. Using Constructors and Destructors to Manage Resources (or RAII)
- Problem
- Solution
- Discussion
- 8.4. Automatically Adding New Class Instances to a Container
- Problem
- Solution
- Discussion
- See Also
- 8.5. Ensuring a Single Copy of a Member Variable
- Problem
- Solution
- Discussion
- 8.6. Determining an Objects Type at Runtime
- Problem
- Solution
- Discussion
- See Also
- 8.7. Determining if One Objects Class Is a Subclass of Another
- Problem
- Solution
- Discussion
- See Also
- 8.8. Giving Each Instance of a Class a Unique Identifier
- Problem
- Solution
- Discussion
- See Also
- 8.9. Creating a Singleton Class
- Problem
- Solution
- Discussion
- See Also
- 8.10. Creating an Interface with an Abstract Base Class
- Problem
- Solution
- Discussion
- 8.11. Writing a Class Template
- Problem
- Solution
- Discussion
- See Also
- 8.12. Writing a Member Function Template
- Problem
- Solution
- Discussion
- See Also
- 8.13. Overloading the Increment and Decrement Operators
- Problem
- Solution
- Discussion
- See Also
- 8.14. Overloading Arithmetic and Assignment Operators for Intuitive Class Behavior
- Problem
- Solution
- Discussion
- See Also
- 8.15. Calling a Superclass Virtual Function
- Problem
- Solution
- Discussion
- 9. Exceptions and Safety
- Introduction
- 9.1. Creating an Exception Class
- Problem
- Solution
- Discussion
- 9.2. Making a Constructor Exception-Safe
- Problem
- Solution
- Discussion
- See Also
- 9.3. Making an Initializer List Exception-Safe
- Problem
- Solution
- Discussion
- See Also
- 9.4. Making Member Functions Exception-Safe
- Problem
- Solution
- Discussion
- 9.5. Safely Copying an Object
- Problem
- Solution
- Discussion
- See Also
- 10. Streams and Files
- Introduction
- 10.1. Lining Up Text Output
- Problem
- Solution
- Discussion
- See Also
- 10.2. Formatting Floating-Point Output
- Problem
- Solution
- Discussion
- See Also
- 10.3. Writing Your Own Stream Manipulators
- Problem
- Solution
- Discussion
- 10.4. Making a Class Writable to a Stream
- Problem
- Solution
- Discussion
- See Also
- 10.5. Making a Class Readable from a Stream
- Problem
- Solution
- Discussion
- See Also
- 10.6. Getting Information About a File
- Problem
- Solution
- Discussion
- 10.7. Copying a File
- Problem
- Solution
- Discussion
- 10.8. Deleting or Renaming a File
- Problem
- Solution
- Discussion
- See Also
- 10.9. Creating a Temporary Filename and File
- Problem
- Solution
- Discussion
- 10.10. Creating a Directory
- Problem
- Solution
- Discussion
- See Also
- 10.11. Removing a Directory
- Problem
- Solution
- Discussion
- See Also
- 10.12. Reading the Contents of a Directory
- Problem
- Solution
- Discussion
- See Also
- 10.13. Extracting a File Extension from a String
- Problem
- Solution
- Discussion
- See Also
- 10.14. Extracting a Filename from a Full Path
- Problem
- Solution
- Discussion
- See Also
- 10.15. Extracting a Path from a Full Path and Filename
- Problem
- Solution
- Discussion
- See Also
- 10.16. Replacing a File Extension
- Problem
- Solution
- Discussion
- See Also
- 10.17. Combining Two Paths into a Single Path
- Problem
- Solution
- Discussion
- See Also
- 11. Science and Mathematics
- Introduction
- 11.1. Computing the Number of Elements in a Container
- Problem
- Solution
- Discussion
- See Also
- 11.2. Finding the Greatest or Least Value in a Container
- Problem
- Solution
- Discussion
- 11.3. Computing the Sum and Mean of Elements in a Container
- Problem
- Solution
- Discussion
- 11.4. Filtering Values Outside a Given Range
- Problem
- Solution
- Discussion
- 11.5. Computing Variance, Standard Deviation, and Other Statistical Functions
- Problem
- Solution
- Discussion
- 11.6. Generating Random Numbers
- Problem
- Solution
- Discussion
- 11.7. Initializing a Container with Random Numbers
- Problem
- Solution
- Discussion
- 11.8. Representing a Dynamically Sized Numerical Vector
- Problem
- Solution
- Discussion
- 11.9. Representing a Fixed-Size Numerical Vector
- Problem
- Solution
- Discussion
- 11.10. Computing a Dot Product
- Problem
- Solution
- Discussion
- See Also
- 11.11. Computing the Norm of a Vector
- Problem
- Solution
- Discussion
- 11.12. Computing the Distance Between Two Vectors
- Problem
- Solution
- Discussion
- 11.13. Implementing a Stride Iterator
- Problem
- Solution
- Discussion
- 11.14. Implementing a Dynamically Sized Matrix
- Problem
- Solution
- Discussion
- See Also
- 11.15. Implementing a Constant-Sized Matrix
- Problem
- Solution
- Discussion
- See Also
- 11.16. Multiplying Matricies
- Problem
- Solution
- Discussion
- See Also
- 11.17. Computing the Fast Fourier Transform
- Problem
- Solution
- Discussion
- 11.18. Working with Polar Coordinates
- Problem
- Solution
- Discussion
- 11.19. Performing Arithmetic on Bitsets
- Problem
- Solution
- Discussion
- See Also
- 11.20. Representing Large Fixed-Width Integers
- Problem
- Solution
- Discussion
- See Also
- 11.21. Implementing Fixed-Point Numbers
- Problem
- Solution
- Discussion
- 12. Multithreading
- Introduction
- 12.1. Creating a Thread
- Problem
- Solution
- Discussion
- See Also
- 12.2. Making a Resource Thread-Safe
- Problem
- Solution
- Discussion
- Using mutexes
- Dangers
- 12.3. Notifying One Thread from Another
- Problem
- Solution
- Discussion
- 12.4. Initializing Shared Resources Once
- Problem
- Solution
- Discussion
- 12.5. Passing an Argument to a Thread Function
- Problem
- Solution
- Discussion
- 13. Internationalization
- Introduction
- 13.1. Hardcoding a Unicode String
- Problem
- Solution
- Discussion
- 13.2. Writing and Reading Numbers
- Problem
- Solution
- Discussion
- See Also
- 13.3. Writing and Reading Dates and Times
- Problem
- Solution
- Discussion
- See Also
- 13.4. Writing and Reading Currency
- Problem
- Solution
- Discussion
- See Also
- 13.5. Sorting Localized Strings
- Problem
- Solution
- Discussion
- 14. XML
- Introduction
- 14.1. Parsing a Simple XML Document
- Problem
- Solution
- Discussion
- See Also
- 14.2. Working with Xerces Strings
- Problem
- Solution
- Discussion
- 14.3. Parsing a Complex XML Document
- Problem
- Solution
- Discussion
- See Also
- 14.4. Manipulating an XML Document
- Problem
- Solution
- Discussion
- 14.5. Validating an XML Document with a DTD
- Problem
- Solution
- Discussion
- See Also
- 14.6. Validating an XML Document with a Schema
- Problem
- Solution
- Discussion
- See Also
- 14.7. Transforming an XML Document with XSLT
- Problem
- Solution
- Discussion
- See Also
- 14.8. Evaluating an XPath Expression
- Problem
- Solution
- Discussion
- See Also
- 14.9. Using XML to Save and Restore a Collection of Objects
- Problem
- Solution
- Discussion
- 15. Miscellaneous
- Introduction
- 15.1. Using Function Pointers for Callbacks
- Problem
- Solution
- Discussion
- 15.2. Using Pointers to Class Members
- Problem
- Solution
- Discussion
- See Also
- 15.3. Ensuring That a Function Doesnt Modify an Argument
- Problem
- Solution
- Discussion
- See Also
- 15.4. Ensuring That a Member Function Doesnt Modify Its Object
- Problem
- Solution
- Discussion
- 15.5. Writing an Operator That Isnt a Member Function
- Problem
- Solution
- Discussion
- 15.6. Initializing a Sequence with Comma-Separated Values
- Problem
- Solution
- Discussion
- Index
- About the Authors
- Colophon
- Copyright