c++中atoi等的意思是什么?

钱能的c++第二版中301页的第22到25行中的语句是什么意思啊?
这些是什么函数?作用是什么?

atoi将字符串转换为整形,形式为int a=atoi( str );示例如下:

将str转换为整形后赋值给a,然后计算a+1并输出。

温馨提示:答案为网友推荐,仅供参考
第1个回答  2008-03-31
将字符串转化成整形数:

// crt_atoi.c
// This program shows how numbers
// stored as strings can be converted to
// numeric values using the atoi functions.

#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( \"%s\" ) = %d\n", str, value );
if (errno == ERANGE)
{
printf("Overflow condition occurred.\n");
}
}

Copy Code
Function: atoi( " -2309 " ) = -2309
Function: atoi( "31412764" ) = 31412764
Function: atoi( "3336402735171707160320" ) = 2147483647
Overflow condition occurred.本回答被提问者采纳
第2个回答  2008-03-31
这个好象也文件操作有关
相似回答