为什么不应该使用的atoi()? [英] Why shouldn't I use atoi()?

查看:592
本文介绍了为什么不应该使用的atoi()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人告诉我,我不应该使用 的atoi() ,那我应该总是使用<一个href=\"http://pubs.opengroup.org/onlinepubs/9699919799/functions/strtol.html\"><$c$c>strtol()代替。这有什么错的atoi(),我不应该使用它?为与strtol()真正正确的事情,而不是使用? (而这与strtol()返回担心的是什么,而不是 INT 的atoi()呢?)

Someone told me that I shouldn't use atoi(), and that I should always use strtol() instead. What's wrong with atoi() that I shouldn't use it? Is strtol() really the right thing to use instead? (And what about the fact that strtol() returns a long, not an int like atoi() does?)

推荐答案

>:

的的atoi()函数被与strtol归入(),但被保持,因为它是在现有code广泛使用。 如果数量不知道是在范围内,()应该是因为与atoi()执行任何错误检查不要求使用与strtol。

The atoi() function is subsumed by strtol() but is retained because it is used extensively in existing code. If the number is not known to be in range, strtol() should be used because atoi() is not required to perform any error checking.

或者

的atoi 是过时

这篇关于为什么不应该使用的atoi()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆