char - C++ - Getting Byte from Console -
i new c++ , coming c# / java background feel kind of spoilt.
what trying achieve here data input user byte (unsigned char
) using cin
.
#include <iostream> using namespace std; typedef unsigned char byte; int main() { byte num = 0; char exitkey = '0'; cout << "type in number between 0 , 255.\n"; cin >> num; cout << "\nyour number multiplied 2 is:\n" << (num * 2); cin >> exitkey; return 0; }
the value returned ascii decimal value of character typed in. how can actual value, treating value number?
help appreciated. thanks.
it doesn't matter type-aliases use, when reading using cin >>
character character, , read character.
the value getting ascii code character '1'
.
if want read number, use proper numeric datatype, int
.
Comments
Post a Comment