请问:C++ atoi函数 怎么用?谢谢大家~

来源:百度知道 编辑:UC知道 时间:2024/06/30 00:46:05

atoi函数原型:
int atoi(char *str)
函数用途:
将字符串转换成一个整数值
输入参数:
str 待转换为整型数的字符串
返回值:
成功返回转换后的数值,失败则返回0.

//example
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>

int main( void )
{
char *str = NULL;
int value = 0;

// An example of the atoi function.
str = " -2309 ";
value = atoi( str );
printf( "Function: atoi( \"%s\" ) = %d\n", str, value );

// Another example of the atoi function.
str = "31412764";
value = atoi( str );
printf( "Function: atoi( \"%s\" ) = %d\n", str, value );

// Another example of the atoi function
// with an overflow condition occuring.
str = "3336402735171707160320";
value = atoi( str );
printf( "Function: atoi