I understand what said functions do, but I can't guess how their names were created, except that the last letter is from the return type.
atoi is a function in the C programming language that converts a string into an integer numerical representation. atoi stands for ASCII to integer.
First, atoi() converts C strings (null-terminated character arrays) to an integer, while stoi() converts the C++ string to an integer. Second, the atoi() function will silently fail if the string is not convertible to an int , while the stoi() function will simply throw an exception.
atof recognizes an optional string of tabs and spaces, then an optional sign, then a string of digits optionally containg a decimal point, then an optional e or E followed by an optionally signed integer. atoi recognizes an optional string of tabs and spaces, then an optional sign, then a string of digits.
atoi -> ASCII to integer.
atol -> ASCII to long.
atof -> ASCII to floating.
stoi -> string to integer.
stol -> string to long.
stoll -> string to long long.
stof -> string to float.
stod -> string to double.
stold -> string to long double.
atoi
, atol
, atof
come from C
and its godfather most probably is considered to be Ken Thompson the co-creator of the UNIX operating system and the creator of the B programming language which is the predecessor of the C programming language. The names are mentioned in the first UNIX Programmer's Manual November 3, 1971 and as you can see in the owner's label ken
is mentioned which is the nickname of Ken Thomson:
stoi
, stol
, stoll
, stof
, stod
and stold
got in C++ since C++11. Consequently, the naming must have been a unanimous decision of the C++ committee. The original proposal N1803 though dates back in 2005. I couldn't find in the proposal why the named these functions after these names. My guess is that probably they wanted to keep the uniformity with their C "equivalents" mentioned above.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With