手机
当前位置:查字典教程网 >编程开发 >C语言 >C++ 如何用cout输出hex,oct,dec的解决方法
C++ 如何用cout输出hex,oct,dec的解决方法
摘要:HEX:复制代码代码如下:#include#includemain(void){longn=10000;cout

HEX:

复制代码 代码如下:

#include <iostream.h>

#include <iomanip.H>

main(void)

{

long n = 10000;

cout << hex << n ;

return 0;

}

OCT:

复制代码 代码如下:

#include <iostream.h>

#include <iomanip.H>

main(void)

{

long n = 10000;

cout << oct << n ;

return 0;

}

DEC:

复制代码 代码如下:

#include <iostream.h>

#include <iomanip.H>

main(void)

{

long n = 10000;

cout << dec << n << endl;

return 0;

}

复制代码 代码如下:

#include <iostream>

using namespace std;

int main()

{

cout.setf(ios::hex, ios::basefield);

cout << 100; // this displays 64

return 0;

}

复制代码 代码如下:

#include <iostream>

#include <iomanip>

using namespace std;

int main()

{

int n;

cout << "Enter a decimal number: ";

cin >> n;

cout << n << " in hexadecimal is: "

<< hex << n << '/n'

<< dec << n << " in octal is: "

<< oct << n << '/n'

<< setbase( 10 ) << n << " in decimal is: "

<< n << endl;

return 0;

}

【C++ 如何用cout输出hex,oct,dec的解决方法】相关文章:

undefined reference to `SetPduPowerConsumptionCnt'错误的解决方法

C++ 关于STL中sort()对struct排序的方法

C与C++ 无参函数的区别解析

C/C++中退出线程的四种解决方法

C++可变参数的实现方法

C++实现两个日期间差多少天的解决方法

解析在WTL下使用双缓冲的实现方法

c/c++输出重定向的方法

去掉vs2010中ipch文件和.sdf文件的解决方法

C++多文件变量解析

精品推荐
分类导航