Skip to content

STYLE: Prefer error checked std::sto[id] over ato[if]

Hans Johnson requested to merge prefer-cpp-exception-thowing-sto_i_d_f into master

The ato[if] functions do not provide mechanisms for distinguishing between '0' and the error condion where the input can not be converted.

std::sto[id] provides exception handling and detects when an invalid string attempts to be converted to an [integer|double].t

atoif Con: No error handling. Con: Handle neither hexadecimal nor octal.

The use of ato[if] in code can cause it to be subtly broken. ato[if] makes two very big assumptions indeed: The string represents an integer/floating point value. The integer can fit into an int.

Merge request reports