手机
当前位置:查字典教程网 >编程开发 >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的解决方法】相关文章:

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

c++ 一个二进制串转化为整数的解决方法

解析C/C++中如何终止线程的运行

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

用C++实现单向循环链表的解决方法

求子数组最大和的解决方法详解

c语言中用字符串数组显示菜单的解决方法

C++函数中return语句的使用方法

用贪心法求解背包问题的解决方法

C++输出斐波那契数列的两种实现方法

精品推荐
分类导航