atoll
函数 <cstdlib>
long long int atoll ( const char * str );
将字符串转换为long long integer
解析C-string str,将其内容解释为整数值,并返回为long long int类型的值。
这个函数类似于atol来解释字符串,但是会产生long long int类型的数字(有关解释过程的详细信息,请参阅
atol)。
☲ 参数
str
以整数表示开头的c字符串。
☉ 返回值
如果成功,函数将转换后的整数值作为long long int值返回。
如果不能执行有效的转换,则返回零值。
如果转换后的值超出了long long int类型可表示值的范围,则会导致未定义的行为。
如果有可能,请参阅
strtoll,以获得更健壮的跨平台替代方案。
☣ 示例
/* atoll example */
#include <stdio.h> /* printf, fgets */
#include <stdlib.h> /* atoll */
int main ()
{
long long int lli;
char buffer[256];
printf ("Enter a long number: ");
fgets (buffer, 256, stdin);
lli = atoll(buffer);
printf ("The value entered is %lld. Its double is %lld.\n",lli,lli*2);
return 0;
}
|
输出:
Enter a number: 9275806
The value entered is 9275806. Its double is 18551612.
↭ 数据竞争
访问str所指向的数组。
❆ 异常(c++)
无抛出保证:此函数从不抛出异常。
如果str没有指向有效的C-string,或者转换后的值超出了long long int可表示值的范围,则会导致未定义的行为。
🍄 另请参阅
strtoll |
将字符串转换为long long integer(function ) |
atoi |
将string转换为integer(function) |
atol |
将string转换为 long integer(function) |