I have human readable numeric data in istream . Values range from 0 to 255, and I want to save them in uint8_t . Unfortunately, if I try something like
uint8_t a, b; stringstream data("124 67"); data >> a >> b;
then I get a == '1' and b == '2' . I understand that in many situations this is the desired behavior, but I want to get a == 124 and b == 67 . My current solution is to stream data to int s, then copy them to uint8_t s.
uint8_t a, b; int a_, b_; stringstream data("124 67"); data >> a_ >> b_; a = a_; b = b_;
Clearly, this is very cumbersome (and a bit inefficient). Is there a cleaner way to read the numeric (as opposed to characters) uint8_t data using stream s?
source share