编一个把整数转换成字符mmm,mmm,mmm格式的函数,例如:f(12345)->123,45.不能用inttostr()等函数,可以用operator函数,谢谢!

解决方案 »

  1.   

    CString IntToCommaString(int nValue)
    {
    CString sText;
    CString sValue;
    BOOL bNegative = FALSE;
    if(nValue < 0)
    {
    sText = "-";
    nValue = - nValue;
    }
    sValue.Format("%d", nValue); int nLength = sValue.GetLength();
    int t = nLength % 3;
    if(t)
    {
    sText += sValue.Left(t);
    if(t != nLength)
    sText += ",";
    } for(int i = t;;)
    {
    sText += sValue.Mid(i, 3);
    if((i += 3) >= nLength)
    break;
    sText += ",";
    }
    return sText;
    }
      

  2.   

    你自己定义一个新的类如CIntSegPointo类,然后再重载=运算符,为
    operation=(int int)
    {
    进行上面bcpl(戒烟直到五颗星)的处理;
    }