header files - What difference does it make when I include <limits> or <limits.h> in my c++ code -
can please explain this?
#include <iostream> #include <limits.h>
or
#include <iostream> #include <limits>
<limits>
c++ standard library header providing similar insights c header <limits.h>
(which available in c++ <climits>
), written in way that's more useful , safe in c++ programs:
say have
template <typename numeric> ...
, , code inside wants know minimum , maximum value ofnumeric
type parameter user instantiated template with: can usestd::numeric_limits<numeric>::min()
,...::max()
; if wanted access same values<climits>
, it'd hard know ofschar_min
,shrt_min
,int_min
,long_min
etc. use , you'd have switch between them - lots of code trivial<climits>
has lots of macros, , macros don't respect namespaces or scopes way "normal" c++ identifiers - substitutions made pretty indescriminately - make program more error prone<limits>
gives more insight numeric types, such whether they're signed, number of base-10 digits can handle, whether can represent infinity or not-a-number sentinel values etc. (see header docs fuller list , information)
Comments
Post a Comment