我了解这些函数的作用,但我无法猜测它们的命名方式,除了最后一个字母是返回类型之外。
我了解这些函数的作用,但我无法猜测它们的命名方式,除了最后一个字母是返回类型之外。
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
源自于C语言,它们的创造者很可能是Ken Thompson,他是UNIX操作系统的共同创建者,并且创建了B编程语言,后者是C语言的前身。这些函数名在1971年11月3日发布的第一版UNIX程序员手册中被提到,在所有者标签中可以看到昵称为"ken"的Ken Thomson的名字。
stoi
、stol
、stoll
、stof
、stod
和stold
被引入到了C++中。因此,这些命名必须是C++委员会的一致决定。但最初的提案N1803可以追溯到2005年。我在提案中找不到为什么要用这些名称来命名这些函数的原因。我的猜测是,他们可能想要保持与上面提到的C语言“等效”函数的统一性。