O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

C++ All-in-One For Dummies, 3rd Edition

Book Description

Get ahead of the C++ curve to stay in the game

C++ is the workhorse of programming languages and remains one of the most widely used programming languages today. It's cross-platform, multi-functional, and updates are typically open-source. The language itself is object-oriented, offering you the utmost control over data usage, interface, and resource allocation. If your job involves data, C++ proficiency makes you indispensable.

C++ All-in-One For Dummies, 3rd Edition is your number-one handbook to C++ mastery. Author John Paul Mueller is a recognized authority in the computer industry, and your ultimate guide to C++. Mueller takes you through all things C++, including information relevant to the 2014 update.

  • Learn how to work with objects and classes

  • Conquer advanced programming and troubleshooting

  • Discover how lambda expressions can make your code more concise and readable

  • See Standard Library features, such as dynamic arrays, in action

  • Online resources include source code from examples in the book as well as a C++ GNU compiler. If you need to learn C++, this is the fastest, most effective way to do it. C++ All-in-One For Dummies, 3rd Edition will get you up and running quickly, so you can get to work producing code faster and better than ever.

    Table of Contents

      1. Introduction
        1. No Experience Necessary
        2. Great for Advanced Folks, Too!
        3. For All Computers
        4. Conventions
        5. Organization
        6. Icons Galore
        7. What’s Next?
        8. Beyond the Book
      2. Book I: Getting Started with C++
        1. Chapter 1: Configuring Your System
          1. Obtaining a Copy of C++ 14
          2. Obtaining Code::Blocks
          3. Installing Code::Blocks
            1. Working with Windows
            2. Working with Mac OS/X
            3. Using the standard Linux installation
            4. Using the graphical Linux installation
          4. Touring the Essential Code::Blocks Features
            1. Starting Code::Blocks for the first time
            2. Opening the sample projects
            3. Viewing the essential windows
          5. Using Other IDEs
        2. Chapter 2: Creating Your First C++ Application
          1. Code::Blocks Creating a Project
            1. Understanding projects
            2. Defining your first project
            3. Building and executing your first application
          2. Typing the Code
          3. Starting with Main
          4. Showing Information
            1. Doing some math
            2. Tabbing your output
          5. Let Your Application Run Away
        3. Chapter 3: Storing Data in C++
          1. Putting Your Data Places: Variables
            1. Creating an integer variable
            2. Declaring multiple variables
            3. Changing values
            4. Setting one variable equal to another
            5. Initializing a variable
            6. Creating a great name for yourself
          2. Manipulating Integer Variables
            1. Adding integer variables
            2. Subtracting integer variables
            3. Multiplying integer variables
            4. Dividing integer variables
          3. Characters
            1. Null character
            2. Nonprintable and other cool characters
          4. Strings
            1. Getting a part of a string
            2. Changing part of a string
            3. Adding onto a string
            4. Adding two strings
          5. Deciding between Conditional Operators
          6. Telling the Truth with Boolean Variables
          7. Reading from the Console
        4. Chapter 4: Directing the Application Flow
          1. Doing This or Doing That
          2. Evaluating Conditions in C++
            1. Finding the right C++ operators
            2. Combining multiple evaluations
          3. Including Evaluations in C++ Conditional Statements
            1. Deciding what if and also what else
            2. Going further with the else and if
          4. Repeating Actions with Statements That Loop
            1. Looping situations
            2. Looping for
            3. Looping while
            4. Doing while
            5. Breaking and continuing
            6. Nesting loops
        5. Chapter 5: Dividing Your Work with Functions
          1. Dividing Your Work
          2. Calling a Function
            1. Passing a variable
            2. Passing multiple variables
          3. Writing Your Own Functions
            1. Multiple parameters or no parameters
            2. Returning nothing
            3. Keeping your variables local
            4. Forward references and function prototypes
            5. Writing two versions of the same function
          4. Calling All String Functions
          5. Understanding main()
        6. Chapter 6: Splitting Up Source Code Files
          1. Creating Multiple Source Files
            1. Splitting a project into multiple source files in Code::Blocks
            2. Creating a project in Code::Blocks with multiple existing files
            3. Multiple source files in other compilers
            4. Creating multiple files
          2. Sharing with Header Files
            1. Adding the header only once
            2. Using brackets or quotes
          3. Sharing Variables among Source Files
          4. Using the Mysterious Header Wrappers
        7. Chapter 7: Referring to Your Data Through Pointers
          1. Heaping and Stacking the Variables
            1. Getting a variable’s address
            2. Changing a variable by using a pointer
            3. Pointing at a string
            4. Pointing to something else
            5. Tips on pointer variables
          2. Dynamically Allocating with new
            1. Using new
            2. Using an initializer
            3. Making new strings
          3. Freeing Pointers
          4. Passing Pointer Variables to Functions
            1. Changing variable values with pointers
            2. Modifying string parameters
          5. Returning Pointer Variables from Functions
          6. Returning a Pointer as a Nonpointer
          7. Passing by Reference
          8. Passing By const Reference
          9. Remembering the Rules
        8. Chapter 8: Working with Classes
          1. Understanding Objects and Classes
            1. Classifying classes and objects
            2. Describing member functions and data
            3. Implementing a class
            4. Separating member function code
            5. The parts of a class
          2. Working with a Class
            1. Accessing members
            2. Using classes and pointers
            3. Passing objects to functions
            4. Using const parameters in functions
            5. Using the this pointer
            6. Overloading member functions
          3. Starting and Ending with Constructors and Destructors
            1. Starting with constructors
            2. Ending with destructors
            3. Sampling constructors and destructors
            4. Adding parameters to constructors
          4. Building Hierarchies of Classes
            1. Creating a hierarchy in C++
            2. Understanding types of inheritance
          5. Creating and Using Object Aliases
        9. Chapter 9: Using Advanced C++ Features
          1. Filling Your Code with Comments
          2. Converting Types
          3. Reading from the Console
          4. Understanding Preprocessor Directives
          5. Using Constants
          6. Using Switch Statements
          7. Supercharging enums with Classes
          8. Working with Random Numbers
          9. Storing Data in Arrays
            1. Declaring and accessing an array
            2. Arrays of pointers
            3. Passing arrays to functions
            4. Adding and subtracting pointers
      3. Book II: Understanding Objects and Classes
        1. Chapter 1: Planning and Building Objects
          1. Recognizing Objects
            1. Observing the Mailboxes class
            2. Observing the Mailbox class
            3. Finding other objects
          2. Encapsulating Objects
          3. Building Hierarchies
            1. Establishing a hierarchy
            2. Protecting members when inheriting
            3. Overriding member functions
            4. Specializing with polymorphism
            5. Getting abstract about things
          4. Discovering Classes
            1. Engineering your software
            2. Finding those pesky classes
        2. Chapter 2: Describing Your Program with UML
          1. Moving Up to UML
            1. Modeling with UML
            2. Diagramming and designing with UML
          2. Building with UML and the Rational Unified Process
            1. Speaking iteratively
            2. Phasing in and out
            3. The inception phase
            4. The elaboration phase
            5. The construction phase
            6. The transition phase
          3. Moving Forward with UML
        3. Chapter 3: Structuring Your Classes with UML
          1. Drawing Classes
            1. Mapping classes with UML
            2. Inheriting in UML
            3. Aggregating and composing classes
          2. Building Components
          3. Deploying the Software
        4. Chapter 4: Demonstrating Behavior with UML
          1. Drawing Objects
          2. Casing Out the Use Cases
            1. Expanding use cases
            2. Matching use cases and requirements
          3. Sequence Diagrams
            1. Notating sequence diagrams
            2. Looping and comparing in sequence diagrams
          4. Collaboration Diagrams
          5. Activity Diagrams
          6. State Diagrams
        5. Chapter 5: Modeling Your Applications with UML
          1. Using UML Goodies
            1. Packaging your symbols
            2. Notating your diagrams
            3. Tagging your symbols
          2. Free to Be UML
          3. C++ and UML
            1. Drawing enumerations
            2. Including static members
            3. Parameterizing classes with templates
        6. Chapter 6: Building with Design Patterns
          1. Introducing a Simple Pattern: the Singleton
          2. Watching an Instance with an Observer
            1. Observers and the Standard C++ Library
            2. Automatically adding an observer
          3. Mediating with a Pattern
      4. Book III: Fixing Problems
        1. Chapter 1: Dealing with Bugs
          1. It’s Not a Bug. It’s a Feature!
          2. Make Your Application Features Look Like Features
          3. Anticipating (Almost) Everything
          4. Avoiding Mistakes, Plain and Simple
        2. Chapter 2: Debugging an Application
          1. Programming with Debuggers
            1. Running the debugger
            2. Recognizing the parts of the Code::Blocks debugger
          2. Debugging with Different Tools
            1. Standard debuggers
          3. Debugging a Code::Blocks Application with Command Line Arguments
        3. Chapter 3: Stopping and Inspecting Your Code
          1. Setting and Disabling Breakpoints
            1. Setting a breakpoint in Code::Blocks
            2. Enabling and disabling breakpoints
          2. Watching, Inspecting, and Changing Variables
            1. Watching the variables
            2. Watching objects
            3. Changing values
        4. Chapter 4: Traveling About the Stack
          1. Stacking Your Data
            1. Moving about the stack
            2. Storing local variables
          2. Debugging with Advanced Features
            1. Viewing threads
            2. Tracing through assembly code
      5. Book IV: Advanced Programming
        1. Chapter 1: Working with Arrays, Pointers, and References
          1. Building Up Arrays
            1. Declaring arrays
            2. Arrays and pointers
            3. Using multidimensional arrays
            4. Arrays and command-line parameters
            5. Allocating an array on the heap
            6. Storing arrays of pointers and arrays of arrays
            7. Building constant arrays
          2. Pointing with Pointers
            1. Becoming horribly complex
            2. Pointers to functions
            3. Pointing a variable to a member function
            4. Pointing to static member functions
          3. Referring to References
            1. Reference variables
            2. Returning a reference from a function
        2. Chapter 2: Creating Data Structures
          1. Working with Data
            1. The great variable roundup
            2. Expressing variables from either side
            3. Casting a spell on your data
            4. Casting safely with C++
            5. Dynamically casting with dynamic_cast
            6. Statically casting with static_cast
          2. Structuring Your Data
            1. Structures as component data types
            2. Equating structures
            3. Returning compound data types
          3. Naming Your Space
            1. Using variables and part of a namespace
        3. Chapter 3: Constructors, Destructors, and Exceptions
          1. Constructing and Destructing Objects
            1. Overloading constructors
            2. Initializing members
            3. Adding a default constructor
            4. Functional constructors
            5. Calling one constructor from another
            6. Copying instances with copy constructors
            7. When constructors go bad: Failable constructors?
            8. Destroying your instances
            9. Virtually inheriting destructors
          2. Programming the Exceptions to the Rule
            1. Throwing direct instances
            2. Catching any exception
            3. Rethrowing an exception
        4. Chapter 4: Advanced Class Usage
          1. Inherently Inheriting Correctly
            1. Morphing your inheritance
            2. Adjusting access
            3. Returning something different, virtually speaking
            4. Multiple inheritance
            5. Virtual inheritance
            6. Friend classes and functions
          2. Using Classes and Types within Classes
            1. Nesting a class
            2. Types within classes
        5. Chapter 5: Creating Classes with Templates
          1. Templatizing a Class
            1. Separating a template from the function code
            2. Including static members in a template
          2. Parameterizing a Template
            1. Putting different types in the parameter
            2. Including multiple parameters
          3. Typedefing a Template
          4. Deriving Templates
            1. Deriving classes from a class template
            2. Deriving a class template from a class
            3. Deriving a class template from a class template
          5. Templatizing a Function
            1. Overloading and function templates
            2. Templatizing a member function
        6. Chapter 6: Programming with the Standard Library
          1. Architecting the Standard Library
          2. Containing Your Classes
            1. Storing in a vector
            2. Mapping your data
            3. Containing instances, pointers, or references
            4. Comparing instances
            5. Iterating through a container
            6. A map of pairs in your hand
          3. The Great Container Showdown
            1. Associating and storing with a set
            2. Unionizing and intersecting sets
            3. Listing with list
            4. Stacking the deque
            5. Waiting in line with stacks and queues
          4. Copying Containers
          5. Creating and Using Dynamic Arrays
            1. Configuring the IDE
            2. Declaring a dynamic array
          6. Working with Unordered Data
            1. Using std::unordered_set to create an unordered set
            2. Manipulating unordered sets
        7. Chapter 7: Working with Lambda Expressions
          1. Creating More Readable and Concise C++ Code
          2. Defining the Essential Lambda Expression
            1. Defining the parts of a lambda expression
            2. Relying on compiler detection of return type
            3. Using a specific return type
            4. Using the auto keyword
          3. Developing Applications with Lambda Expressions
            1. Creating lambda expressions with multiple inputs
            2. Working with the capture clause
            3. Sorting data using a lambda expression
            4. Specifying that the lambda expression throws exceptions
      6. Book V: Reading and Writing Files
        1. Chapter 1: Filing Information with the Streams Library
          1. Seeing a Need for Streams
          2. Programming with the Streams Library
            1. Getting the right header file
            2. Opening a file
          3. Handling Errors When Opening a File
          4. Flagging the ios Flags
        2. Chapter 2: Writing with Output Streams
          1. Inserting with the << Operator
          2. Formatting Your Output
            1. Formatting with flags
            2. Specifying a precision
            3. Setting the width and creating fields
        3. Chapter 3: Reading with Input Streams
          1. Extracting with Operators
          2. Encountering the End of File
          3. Reading Various Types
          4. Reading Formatted Input
        4. Chapter 4: Building Directories and Contents
          1. Manipulating Directories
            1. Creating a directory
            2. Deleting a directory
          2. Getting the Contents of a Directory
          3. Copying Files
          4. Moving and Renaming Files and Directories
        5. Chapter 5: Streaming Your Own Classes
          1. Streaming a Class for Text Formatting
          2. Manipulating a Stream
            1. What’s a manipulator?
            2. Writing your own manipulator
      7. Book VI: Advanced C++
        1. Chapter 1: Exploring the Standard Library Further
          1. Considering the Standard Library Categories
            1. Containers
            2. Iterators
            3. Algorithms
            4. Functors
            5. Utilities
            6. Adaptors
            7. Allocators
            8. Polymorphic allocators
          2. Parsing Strings Using a Hash
          3. Obtaining Information Using a Random Access Iterator
          4. Locating Values Using the Find Algorithm
          5. Using the Random Number Generator
          6. Performing Comparisons Using min and max
          7. Working with Temporary Buffers
        2. Chapter 2: Working with User-Defined Literals (UDLs)
          1. Understanding the Need for UDLs
            1. Prefixes and suffixes
            2. Differentiating between raw and cooked
          2. Working with the UDLs Included in the Standard Library
            1. std::basic_string
            2. std::complex
            3. std::chrono::duration
          3. Creating Your Own UDLs
            1. Developing a conversion UDL
            2. Developing a custom type UDL
            3. Using a custom UDL for side effects
        3. Chapter 3: Building Original Templates
          1. Deciding When to Create a Template
          2. Defining the Elements of a Good Template
          3. Creating a Basic Math Template
          4. Building a Structure Template
          5. Developing a Class Template
          6. Considering Template Specialization
          7. Creating a Template Library
            1. Defining the library project
            2. Configuring the library project
            3. Coding the library
          8. Using Your Template Library
        4. Chapter 4: Investigating Boost
          1. Understanding Boost
            1. Boost features
            2. Licensing
            3. Paid support
          2. Obtaining and Installing Boost for Code::Blocks
            1. Unpacking Boost
            2. Using the header-only libraries
            3. Building the libraries
            4. Testing the installation
          3. Creating the Boost Tools
          4. Using Boost.Build
            1. Getting a successful build
            2. Using the examples
          5. Using Regression
          6. Using Inspect
          7. Understanding BoostBook
          8. Using QuickBook
          9. Using bcp
          10. Using Wave
          11. Building Your First Boost Application Using Date Time
        5. Chapter 5: Boosting up a Step
          1. Parsing Strings Using RegEx
            1. Adding the RegEx library
            2. Creating the RegEx code
          2. Breaking Strings into Tokens Using Tokenizer
          3. Performing Numeric Conversion
          4. Creating Improved Loops Using Foreach
          5. Accessing the Operating System Using Filesystem
      8. Appendix: Automating Your Applications with Makefiles
        1. Compiling and Linking
        2. Automating Your Work
        3. Implying with Inference Rules
          1. Using rules that depend on other rules
          2. Making specific items
          3. Depending on multiple files
          4. Compiling and linking with make
          5. Cleaning up and making it all
          6. Using macros
          7. Getting the most out of Makefiles
      9. About the Authors
      10. Cheat Sheet
      11. More Dummies Products