Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do atoi, atol, and stoi stand for? [duplicate]

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.

like image 457
yesennes Avatar asked Jun 15 '16 14:06

yesennes


People also ask

What does atoi stand for?

atoi is a function in the C programming language that converts a string into an integer numerical representation. atoi stands for ASCII to integer.

What is the difference between atoi and stoi?

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.

What is atoi and ATOF?

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.


1 Answers

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:

enter image description here

enter image description here

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.

like image 198
101010 Avatar answered Sep 28 '22 02:09

101010