本人在做MFC的程序的查询时,遇到这样一个问题: 
就是EDIT框中输入一个字符串,但我在查询时需要知道这个框的值是否是一个整型的。 
记得好像早math函数中有一个判断是否为整型的函数,记得也不是很清楚了。 
希望各位高手能够给小弟一些意见吧。谢谢!

解决方案 »

  1.   

    你可以给那个edit变量类型为int这样就可以直接得到你输入的数据是不是整型了。
    有一个是isdigit()判断是不是整型,但是不是在math中,是在<ctype.h>中。
      

  2.   

    CString string;
    BOOL bIsDigit = TRUE;
    int n;
    char ch;        m_wndEdit.GetWindowText(string);
    for (int i = 0;i < string.GetLength();i++)
    {
    ch = string.GetAt(i);
    n = (int)ch;
    if (n < 48 || n > 57)
    bIsDigit = FALSE;
    } if (bIsDigit)
    MessageBox("是整数");
    else
    MessageBox("不是整数");
      

  3.   

    CHouse10000 的方法就可以了,bIsDigit   =   FALSE; 
    加个break;
      

  4.   


            CString str=..., temp;   //temp 为辅助variable temp.Format("%ld", _tcstol(str.GetBuffer(255), NULL, 10) );  // base=10 or 16
    if (temp.GetLength() == str.GetLength())
    cout<<"ALL digital numbers!"<<endl;
      

  5.   

    转换一下
    就用atoi就行了include <stdlib.h>
    #include <stdio.h>void main( void )
    {
       char *s; double x; int i; long l;   s = "  -2309.12E-15";    /* Test of atof */
       x = atof( s );
       printf( "atof test: ASCII string: %s\tfloat:  %e\n", s, x );   s = "7.8912654773d210";  /* Test of atof */
       x = atof( s );
       printf( "atof test: ASCII string: %s\tfloat:  %e\n", s, x );   s = "  -9885 pigs";      /* Test of atoi */
       i = atoi( s );
       printf( "atoi test: ASCII string: %s\t\tinteger: %d\n", s, i );   s = "98854 dollars";     /* Test of atol */
       l = atol( s );
       printf( "atol test: ASCII string: %s\t\tlong: %ld\n", s, l );
    }
    Outputatof test: ASCII string:   -2309.12E-15   float:  -2.309120e-012
    atof test: ASCII string: 7.8912654773d210   float:  7.891265e+210
    atoi test: ASCII string:   -9885 pigs      integer: -9885
    atol test: ASCII string: 98854 dollars      long: 98854
    从中应该有启发
      

  6.   

    一般的,看atoi的返回值即可
    The return value is 0 (for atoi and _atoi64), 0L (for atol), or 0.0 (for atof) if the input cannot be converted to a value of that type
      

  7.   

    真的很谢谢大家!
    我想要补充些,是这样子的,这个Edit框,也可以输入字符串,但当我选择 前面一个字段(数据库表中对应的)为int类型时,比如查询的关系式中间是= 这是如果右边是字符串就会报错。我是想在用户 按下 查询按钮时 ,先判断输入的内容是否为int类型,是查询顺利,否则提示输入的信息不正确,就不再精心sql语句的执行。
      

  8.   

    //如搂主所述,只要将Edit关联一个整形变量,这样将不允许输入非整形的数据。
    //判断是否为整形,IsDigit()
      

  9.   


            CString str; //str 为你要测试的
        BOOL bInt= TRUE;// 是否为整数
    int iThis = atoi(str);
    CString strTemp;
    strTemp.Format("%d", iThis);
    if( str != strTemp && str != "")
    {
    bInt = FALSE;
    }