1字节整数数据类型 [英] 1 byte integer data type
本文介绍了1字节整数数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我写了以下代码:
#include< iostream&
#include< iomanip>
#include< stdint.h>
using namespace std;
int main()
{
uint8_t c;
cin>> hex>> C;
cout<< dec<< C;
return 0;
}
但是当我输入 c
— hex for 12—输出也是 c
。我期待着12.后来我了解到:
uint8_t
通常是typedefunsigned char
。因此,它实际上是以ASCII 0x63读取c
。
整数在执行I / O时不作为整数,而不是作为char?
解决方案
不是我知道的。 >
您可以使用更宽的整数类型来执行I / O,并根据需要使用范围检查和转换。
I wrote the following code:
#include <iostream>
#include <iomanip>
#include <stdint.h>
using namespace std;
int main()
{
uint8_t c;
cin >> hex >> c;
cout << dec << c;
return 0;
}
But when I input c
—hex for 12—the output is also c
. I was expecting 12. Later I learned that:
uint8_t
is usually a typedef forunsigned char
. So it's actually readingc
as ASCII 0x63.
Is there a 1 byte integer which behaves as an integer while doing I/O and not as char?
解决方案
Not that I know of.
You could do the I/O using a wider integer type, and use range checking and casting as appropriate.
这篇关于1字节整数数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文