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?