atoi
来自cppreference.com
< cpp | string/byte
语法:
#include <cstdlib> int atoi( const char *str );
atoi 函数将str转换为整数,并返回此整数。str应该以空白字符或者数字开头,一旦在str中读到非数字字符atoi将停止读取。例如:
int i; i = atoi( "512" ); i = atoi( "512.035" ); i = atoi( " 512.035" ); i = atoi( " 512+34" ); i = atoi( " 512 bottles of beer on the wall" );
上面对 i 的五个赋值都将 i 设置为512.
如果转换不能进行,atoi将返回零:
int i = atoi( " does not work: 512" ); // 结果 i == 0
可以使用 cn/c/io/sprintf 将数字转换为为字符串。
相关主题: atof, atol, cn/c/io/sprintf