Tip Bank

DevX

The #error Preprocessor Directive

During the preprocessing phase, you can report errors by using the #error preprocessor directive. For example, suppose you have a program that uses 64-bit integers. This program has to be

DevX

<iostream.h> or <iostream>?

Although the library was deprecated for several years, many C++ users still use it in new code instead of using the newer, standard compliant library. What are the differences between

DevX

Generating Random Float Values

To generate random floating numbers, choose a floating point number, divide it by the largest value of int type and multiply the result by the value of a function that

DevX

Controlling Floating Point Precision

You can override the default number of digits after the decimal point by calling the precision() member function of an ostream object. The following program first displays six digits after

DevX

std::vector Iterators

To create an iterator of a vector, you have to use a vector specialization. In the following examples, I create two vector iterators: one for the specialization vector and another

DevX

Octal and Hexadecimal Output

By default, cout displays integral values as decimal numbers. You can override this setting and have integral values displayed in hexadecimal and octal notations by using the ‘hex’ and ‘oct’

DevX

Casting To and From void*

In C++, pointers are strongly-typed. Therefore, you can’t assign a void pointer to any other pointer type without casting it explicitly: int n;void *p = &n;int *pi=static_cast< int* >(p);//C++ requires