被isdigit()戏弄了。

来源:互联网 发布:客户细分python 编辑:程序博客网 时间:2024/04/30 06:16

今天和cctype里面的isdigit()躲猫猫,我找了一个小时,才找到它。

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

(把数字放入数组,遇到非数字时结束输入)





//数字输入检验与isdigit(char)

#include <iostream>

#include <cctype>

#include <array>

using namespacestd;

const intSIZE=10;

 

int main()

{

      array<double,SIZE>donation;

      inti=0;

      doubletemp,sum=0.0;

      while(cin>>temp&&i<SIZE&&!isdigit(temp))


那个感叹号,唉。


。。简化版。

        int ch;
cin>>ch;
if (isdigit(ch))
       cout<<"abc";
else cout<<"NONONO";

输入12.输出是NONONO。

把int换为char。输入12.输出是abc。

看来字符和数字的差别和函数还不熟悉。

~~~~~~~~~~~~~~


10进制的字符转数字,假设字符为变量a
a-'0'
变量转字符 n为int型数字(单个位)
n +'0'





0 0