不太想用log之类的函数
比如我要求用户输入不能超过N位长度的整数,这个N是可变的当然,最简单的办法是
if(i >= pow(10, N))
{
数字超过长度。
}

解决方案 »

  1.   

    DWORD dwValue = 12353546;
    int nPos = 1;
    while(dwValue/10)
    {
    dwValue = dwValue/10;
    ++nPos;
    }
    CString strText(_T(""));
    strText.Format(_T("%d"), nPos);
    AfxMessageBox(strText);这样???
      

  2.   

    int GetIntDigit(int nValue)//得到nValue的位数
    {
    int nPos = 1;
    while(nValue/10)
    {
    nValue = nValue/10;
    ++nPos;
    }
    return nPos
    }
      

  3.   

    那样还不如log呢你们没有抓住事件的本质,
    if(strlen(itoa(i))>N)
    {}
      

  4.   

    估计itoa里面也用到了2楼那样的方法,还不如用他那个呢