unsigned char ci;
unsigned short si;
unsigned int ii;
long li;我想用
CString str;
str.Format("ci is %?,si is %?,ii is %?,li is %?",ci,si,ii,li);又问下面这种情况
if(int(ci)==0)
{
//请问,ci是不是已经是int型的了,即,if语句产生了负作用
}

解决方案 »

  1.   

    printf Type Field CharactersCharacter Type Output Format 
    c int or wint_t When used with printf functions, specifies a single-byte character; when used with wprintf functions, specifies a wide character. 
    C int or wint_t When used with printf functions, specifies a wide character; when used with wprintf functions, specifies a single-byte character. 
    d int Signed decimal integer. 
    i int  Signed decimal integer. 
    o int  Unsigned octal integer. 
    u int  Unsigned decimal integer. 
    x int Unsigned hexadecimal integer, using “abcdef.” 
    X int Unsigned hexadecimal integer, using “ABCDEF.” 
    e  double Signed value having the form [ – ]d.dddd e [sign]ddd where d is a single decimal digit, dddd is one or more decimal digits, ddd is exactly three decimal digits, and sign is + or –. 
    E double Identical to the e format except that E rather than e introduces the exponent. 
    f double Signed value having the form [ – ]dddd.dddd, where dddd is one or more decimal digits. The number of digits before the decimal point depends on the magnitude of the number, and the number of digits after the decimal point depends on the requested precision. 
    g double Signed value printed in f or e format, whichever is more compact for the given value and precision. The e format is used only when the exponent of the value is less than –4 or greater than or equal to the precision argument. Trailing zeros are truncated, and the decimal point appears only if one or more digits follow it. 
    G double Identical to the g format, except that E, rather than e, introduces the exponent (where appropriate). 
    n  Pointer to integer  Number of characters successfully written so far to the stream or buffer; this value is stored in the integer whose address is given as the argument. 
    p Pointer to void Prints the address pointed to by the argument in the form xxxx:yyyy where xxxx is the segment and yyyy is the offset, and the digits x and y are uppercase hexadecimal digits. 
    s String  When used with printf functions, specifies a single-byte–character string; when used with wprintf functions, specifies a wide-character string. Characters are printed up to the first null character or until the precision value is reached. 
    S String When used with printf functions, specifies a wide-character string; when used with wprintf functions, specifies a single-byte–character string. Characters are printed up to the first null character or until the precision value is reached. 
      

  2.   

    str.Format("ci is %c,si is %d,ii is %d,li is %f",ci,si,ii,li);
      

  3.   

    如果你的ci,si,ii,li是整型
    那么
    str.Format("ci is %d,si is %d,ii is %d,li is %d",ci,si,ii,li);如果你的ci,si,ii,li是字符型
    那么
    str.Format("ci is %s,si is %s,ii is %s,li is %s",ci,si,ii,li);如果你的ci,si,ii,li是符点型
    那么
    str.Format("ci is %s,si is %f,ii is %f,fli is %f",ci,si,ii,li);format语句不会对ci的类型产生影响!
      

  4.   

    去看MSDN。if(int(ci)==0)
    {
    //请问,ci是不是已经是int型的了,即,if语句产生了负作用
    }
    不会影响ci的,他原来是什么现在还是什么。如果用 %d来打印,那就是他的ASII值。
      

  5.   

    CString str;
    str.Format("ci is %u,si is %u,ii is %u,li is %d",ci,si,ii,li);又问下面这种情况
    if(int(ci)==0)
    {
    //请问,ci是不是已经是int型的了,即,if语句产生了负作用
    }
    答:不是,ci没有改变类型。
    int()强制转换是有返回值的。比如int i = int(ci);因此,这里相当于if(i==0)
      

  6.   

    你可以用ANSI C 里的sprintf
    sprintf(buf, "%d", int_x)也可以用ISO C++ 的strstream
    strstream strbuf;
    strbuf <<  int_x;if(int(ci)==0)
    这条语句并不改变ci的类型
    只是表达式int(ci)这是是int型
      

  7.   

    请问楼上兄弟,long 型 的可以直接用%d转啊, 
    还有,unsign char 直接用 %u,那是不是 char型就可以直接用 %d了
      

  8.   

    因为我认为如果是 long li;
    那么应该是str.Format(“%ld”,li);不知道对不对啊,我急着要用这类转换,先谢谢大伙了。
    马上就揭贴了
      

  9.   

    d int  Signed decimal integer. 
    i int  Signed decimal integer. 
    o int  Unsigned octal integer. 
    u int  Unsigned decimal integer. 
    都是可以的。十进制的可以用d和u。在32位机器上,long型用%d也是没有问题的
      

  10.   

    if(int(ci)==0)是判断字符是否是ascii码0
      

  11.   

    呵呵,要把字符型转换成整型可以用atoi