我是靠谱客的博主 落后电源,这篇文章主要介绍C++中的atoi 函数简介,现在分享给大家,希望可以做个参考。

一.atoi 函数

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

语法如下:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/* *描述:将一个char类型转为整数 * *参数: * [in] string:字符串类型 * *返回值:返回char类型对应的整数 */ int atoi(char *string);

二.atoi 函数函数实战

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#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

请按任意键继续. . .

到此这篇关于C++中的atoi 函数简介的文章就介绍到这了,更多相关atoi 函数简介内容请搜索靠谱客以前的文章或继续浏览下面的相关文章希望大家以后多多支持靠谱客!

最后

以上就是落后电源最近收集整理的关于C++中的atoi 函数简介的全部内容,更多相关C++中内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(111)

评论列表共有 0 条评论

立即
投稿
返回
顶部