将char转换为int。 [英] Converting char to int.

查看:81
本文介绍了将char转换为int。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!


我知道这听起来像个愚蠢的问题,但我需要改变是否

不是一个字母(来自char array)是一个数字。我用atoi试过了

,但对于任何角色来说它似乎都会返回0。这没关系,

除非该字符碰巧是''0'。我确定我在这里错过了一些东西。任何指针都会很棒。

数组中的每个字符都是单独变化的,并且使用所有字符数字构建新的字符串流字符串

。所有字母都是字母(或者

至少''应该是''ommited。


提前谢谢。


Daz

Hi all!

I know this sounds like a stupid question, but I need to varify whether
ot not a single char (from a char array) is a number. I have tried
using atoi, but it seems to return ''0'' for any characters. This is ok,
unless the character happens to be a ''0''. I am certain I am missing
something here. Any pointers would be fantastic. Each character in the
array is varified individually and a new stringstream string is built
using all of chars that are numbers. All chars that are letters are (or
at least ''should be'' ommited.

Thanks in advance.

Daz

推荐答案

Daz写道:
Daz wrote:
大家好!

我知道这听起来像个愚蠢的问题,但是我需要改变是否单个char(来自char数组)是一个数字。
Hi all!

I know this sounds like a stupid question, but I need to varify whether
ot not a single char (from a char array) is a number.




查找函数std :: isdigit()。就是这样。



Look up the function std::isdigit(). It does exactly that.




Rolf Magnus写道:

Rolf Magnus wrote:
查找函数std :: isdigit()。它就是这样。
Look up the function std::isdigit(). It does exactly that.




呵呵。巧妙!


谢谢Rolf!:)



Hehe. Ingenious!

Thanks Rolf! :)




Rolf Magnus写道:

Rolf Magnus wrote:
查找函数std :: isdigit()。它就是这样。
Look up the function std::isdigit(). It does exactly that.




裤子!我甚至无法正确引用文字......


再次感谢Rolf!



Pants! I can''t even quote text properly...

Thanks again Rolf!


这篇关于将char转换为int。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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