November 29, 2001

Use enum Types in switch Statements

Certain compiler and code analyzers can detect a missing enumerator in a switch statement. Consider: enum Seasons{ Winter, Spring, Summer, Fall};switch (s){case Winter: wearCoat(); break;case Spring: pruneGarden(); break;case Summer: goSwimming();

Concatenating Variables

If you need to concatenate variables of different types to form a string, use a stringstream object. The header contains the declarations of the stringstream family of classes. Using its

Reading a String from the Standard Input

There are two methods of reading a string from the standard input. The first one uses getline(), as in the following example: std::string name;getline(cin, name); // option #1 The second

Floating Point Types

C++ defines three floating points datatypes: float, double and long double. Some existing implementations support only two (and in some cases only one) of these three. On such implementations, double

Setting a New Handler

The function std::set_new_handler() installs a function to be called when the global operator new or the global operator new[] fail. By default, operator new throws an exception of type std::bad_alloc