手机
当前位置:查字典教程网 >编程开发 >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++ 无参函数的区别解析

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

VC6.0打开文件以及向工程中添加文件时程序崩溃自动退出解决方法

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

求素数,用vector存储的实现方法

基于VC中使用ForceInclude来强制包含stdafx.h的解决方法

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

使用root权限运行自己所编译程序的解决方法

Microsoft Visual C++ 程序的部署方法

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

精品推荐
分类导航