怎样把十进制转为十六进制?相反十六到十呢?
好像intToHex()函数不能用

解决方案 »

  1.   

    intToHex是.net 里面的函数吧?
      

  2.   

    如是字符串可用Sprintf(sfsfs,"%O",sdfsd)l;
      

  3.   

    #include "iostream.h"void main()
    {
    int n=0; cin>>n;
    cout<<hex<<n<<endl;
    }也可以定义自己的“可流类”(从iostream继承),将转换后的16进制字串存储起来,以备使用
      

  4.   

    #include "iostream.h"void main()
    {
    int n=0; cin>>hex>>n;
    cout<<dec<<n<<endl;
    }
    忘了,这是相反的16->10
      

  5.   

    我再说清楚点:
    比如十进制的数10,转为十六进制为A
    不能用cout<<hex这类的,我是VC中写成类似下面的函数:
    char DecToHex(int DecNum)
    输入一个十进制数,返回一个十六进制数
    还不懂吗?
      

  6.   

    楼上高人,请再说清楚点,或阅读Tom Swan: 《Essential C++》。谢
      

  7.   

    在你的DecToHex函数中声明ostream对象,使用<<、>>运算符和控制符(hex、dec、oct、bin)格式化数据,输出ostream对象中的字符串。转“数”(不是数字)的话,则char *还不懂吗?
      

  8.   

    dec to hex string
    fscanf(you_string, "%x", dec);hex to dec string
    fscanf(dec_string, "%d", hex);
    ???
      

  9.   

    #include <iostream.h>
    #include <strstrea.h>char DecToHex(int iDec)
    { strstreambuf sbuf;

    ostream os(&sbuf); os<<hex<<iDec; return sbuf.sgetc();
    }void main()
    {
    cout<<DecToHex(15)<<endl;
    }
      

  10.   

    字符串版:#include <iostream.h>
    #include <strstrea.h>char *DecToHex(int iDec)
    {
    strstreambuf sbuf;

    ostream os(&sbuf); os<<hex<<iDec; return sbuf.str();
    }void main()
    {
    unsigned int i=0;
    char *ac=NULL; for (i=0; i<1000; ++i)
    {
    ac=DecToHex(i);
    cout<<ac<<endl;
    delete ac;
    ac=NULL;
    }
    }还不懂吗?
      

  11.   

    http://expert.csdn.net/Expert/topic/1417/1417315.xml?temp=4.237002E-02