目录
  • 一.atoi 函数
  • 二.atoi 函数函数实战

C++中的atoi 函数简介

一.atoi 函数

stdlib.hatoi 函数,可用于将 char 字符串转为 int 整数类型,

语法如下:

/*

*描述:将一个char类型转为整数

*

*参数:

*   [in] string:字符串类型

*

*返回值:返回char类型对应的整数

*/

int atoi(char *string);

二.atoi 函数函数实战

#include "stdafx.h"

#include <stdio.h>

#include "windows.h"

#pragma warning(disable: 4996)

int _tmain(int argc, _TCHAR* argv[])

{

    printf("atoi函数计算结果 %d \n", atoi("13456"));

    printf("atoi函数计算结果 %d \n", atoi("0"));

    printf("atoi函数计算结果 %d \n", atoi("789"));

    printf("atoi函数计算结果 %d \n", atoi("123.123")); //默认转为整数

    printf("atoi函数计算结果 %d \n", atoi("-9"));

    system("pause");

    return 0;

}

输出:

atoi函数计算结果 13456

atoi函数计算结果 0

atoi函数计算结果 789

atoi函数计算结果 123

atoi函数计算结果 -9

请按任意键继续. . .

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。