Chapter 8. Using Advanced C++ Features

In This Chapter

  • Using comments

  • Working with conversions, consoles, and preprocessor directives

  • Manipulating constants, enums, and random numbers

  • Structuring your code with switch statements

  • Managing arrays of data

C++ has so much to offer that we thought we'd give you a mixture of advanced topics you can explore in C++. So for starters, we're going to talk a bit about some fundamental issues in C++ that become important as you advance your programming career.

Filling Your Code with Comments

We have a task for a friend of ours. We want him to turn our refrigerator around and repair the compressor. We're not going to give him any details about how to do this, and we don't want him to look in a manual. Just grab the tools, go at it, and try to fix the thing. Now doesn't that sound like fun?

Unless he happens to be an expert on refrigeration devices, it's doubtful that he'd get very far, especially without hurting himself.

Now in computer programming, the risk of hurting yourself is pretty low, barring things like monitors falling on you or keyboards jumping up and attacking you. Nevertheless, other people occasionally have to fix your programs, so it's a good idea for you to provide adequate explanations of what your programs do.

How do you explain your programs? You put what are called comments in your code. A comment is simply some words in the code that the compiler ignores and you put in for the benefit of the humans reading the code.

For example, you ...

Get C++ All-In-One For Dummies®, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.