devxlogo

Tip Bank

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

<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

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

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

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

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’

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

Null Pointers and Delete

C++ guarantees that operator delete checks its argument for null-ness. If the argument is 0, the delete expression has no effect. In other words, deleting a null pointer is a