atoi 函数简介 C++中的atoi 函数简介

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

atoi 函数简介 C++中的atoi 函数简介

猿说编程   2021-11-27 我要评论
想了解C++中的atoi 函数简介的相关内容吗,猿说编程在本文为您仔细讲解atoi 函数简介的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:C++atoi 函数,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

请按任意键继续. . .

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们