| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 708 人关注过本帖
标题:不能判断是不是数字,望指点
只看楼主 加入收藏
nalnait
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2006-12-29
收藏
 问题点数:0 回复次数:8 
不能判断是不是数字,望指点

#include<iostream.h>
#include<ctype.h>
void main()
{
int x;
cin>>x;
if(isdigit(x))
cout<<x<<" true "<<endl;
cout<<isdigit(x)<<endl;
}

搜索更多相关主题的帖子: 数字 判断 
2007-01-03 07:36
yushui
Rank: 3Rank: 3
等 级:论坛游民
威 望:7
帖 子:1355
专家分:22
注 册:2006-7-19
收藏
得分:0 
isdigit(x)无论输什么进去得到的都是0

fighting!from now on!
2007-01-03 09:47
yuyunliuhen
Rank: 6Rank: 6
等 级:贵宾
威 望:20
帖 子:1435
专家分:0
注 册:2005-12-12
收藏
得分:0 

#include<iostream.h>
#include<ctype.h>
void main()
{
int x;
cin>>x;
if (isdigit(x)) {
cout << x<< " is a digit\n";
}
else {
cout <<x << " is not a digit\n";
}

}


Go confidently in the  directions of your dreams,live the life you have imagined!Just do it!
It is no use learning without thinking!
2007-01-03 11:22
yushui
Rank: 3Rank: 3
等 级:论坛游民
威 望:7
帖 子:1355
专家分:22
注 册:2006-7-19
收藏
得分:0 
isdigit(x)这个的值始终为0啊 所以输出的一直是else里面的内容

fighting!from now on!
2007-01-03 12:03
yuyunliuhen
Rank: 6Rank: 6
等 级:贵宾
威 望:20
帖 子:1435
专家分:0
注 册:2005-12-12
收藏
得分:0 
isdigit()函数的参数实质上是一个ASCII字符。数字所对应胡ASCII 48-57.所以isdigit(48)的结果是真;isdigit(65)的结果是假,因为ASCII值为65的是字符'a',内容a当然不是数字了。


Go confidently in the  directions of your dreams,live the life you have imagined!Just do it!
It is no use learning without thinking!
2007-01-03 12:28
yuyunliuhen
Rank: 6Rank: 6
等 级:贵宾
威 望:20
帖 子:1435
专家分:0
注 册:2005-12-12
收藏
得分:0 
以下是引用yushui在2007-1-3 12:03:42的发言:
isdigit(x)这个的值始终为0啊 所以输出的一直是else里面的内容

如果按楼上说的情况,那么无论怎么都会输出  ’X‘is not a digit。  看下面:

图片附件: 游客没有浏览图片的权限,请 登录注册

[此贴子已经被作者于2007-1-3 12:30:07编辑过]


Go confidently in the  directions of your dreams,live the life you have imagined!Just do it!
It is no use learning without thinking!
2007-01-03 12:29
一二三四五
Rank: 3Rank: 3
等 级:新手上路
威 望:8
帖 子:856
专家分:0
注 册:2006-11-13
收藏
得分:0 
它传入的是ASCII码

hey,di va la
2007-01-03 12:55
caiqiufu
Rank: 1
等 级:新手上路
帖 子:93
专家分:0
注 册:2006-12-14
收藏
得分:0 
#include<iostream.h>
#include<ctype.h>
void main()
{
char x;//是判断字符是不是数字,而不是判断数字是不是数字.
cin>>x;
if(isdigit(x))
cout<<x<<" true "<<endl;
cout<<isdigit(x)<<endl;
}
2007-01-05 15:23
游乐园
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:671
专家分:0
注 册:2006-11-1
收藏
得分:0 
3楼正解

int isdigit() //只是判断输入的字符是否是属于'0'-'9' 是则返回1 不是返回0

unicorn-h.spaces. ◇◆ sava-scratch.spaces.
2007-01-05 17:33
快速回复:不能判断是不是数字,望指点
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.013110 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved