Department of Engineering

IT Services

Use <climits> to access information on the system's limits. E.g. to check if a long variable can fit into a short you could try

long i;
if (i<numeric_limits<short>::min() || numeric_limits<short>::max() <i)
     cout << i << "cannot fit into a short"