This is because uint8_t
is usually a typedef
for unsigned char
. So it's actually reading 'c'
as ASCII 0x63
.
Use int
instead.
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int c;
cin>>hex>>c;
cout<<dec<<c<<'\n';
return 0;
}
Program output:
$ g++ test.cpp $ ./a.out c 12