为什么最后一个十六进制结果是0 * 43?为什么不是43? [英] Why the last hex result is 0*43? Why is not 43?

查看:164
本文介绍了为什么最后一个十六进制结果是0 * 43?为什么不是43?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include<iostream>
using namespace std;
int main()
{
	int x;
	cout<<"Enter an int:";
	cin>>x;
	cout<<hex<<x<<endl
	    <<oct<<x<<endl;
	cout<<x<<endl;
	cout<<showbase<<dec<<x<<endl;
	cout<<showbase<<hex<<x;
	return 0;
}





我的问题是为什么最后一个十六进制结果是0 * 43?为什么不是43?

因为这个程序的结果是这样的:

输入一个int:67

43

103

103

67

0x43



我的尝试: < br $>


我搜索了这个,我看到了这个结果:当设置showbase格式标志时,插入到输出流中的数字整数值前缀为使用的相同前缀C ++文字常量:十六进制值为0x(参见十六进制),八进制值为0(参见oct),十进制基值没有前缀(参见十进制)。

但是这有特殊原因吗0 *或八进制必须是0?



My question is Why the last hex result is 0*43?why is not 43?
becuase result of this program is like this:
Enter an int:67
43
103
103
67
0x43

What I have tried:

I have searched about this and i saw this result:"When the showbase format flag is set, numerical integer values inserted into output streams are prefixed with the same prefixes used by C++ literal constants: 0x for hexadecimal values (see hex), 0 for octal values (see oct) and no prefix for decimal-base values (see dec)."
But does this have special cause that 0*or for octal it must be with 0?

推荐答案

你已经回答了自己的问题



它是0x43,因为 showbase 插入0x



你没有使用 showbase 八进制 cout - 如果你是,第2行将是 0103





(而且它是'x',而不是'*')
you've answered your own question

it's 0x43 because showbase inserts the 0x

You're not using showbase on the octal cout - if you were, line #2 would be 0103


(and it's an 'x', not an '*')


这篇关于为什么最后一个十六进制结果是0 * 43?为什么不是43?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆