[Solved] istringstream to int8_t produce unexpected result


The problem is int8_t is implemented as char.

The implementation of the input stream is working like this:

char x;
std::string inputString = "abc";
std::istringstream is(inputString);

is >> x;
std::cout << x;

The result is ‘a’, because for char the input stream is read char for char.

To solve the problem, provide a specialised implementation for your template method. and reading into a int, then check the bounds and convert the value into a int8_t.

0

solved istringstream to int8_t produce unexpected result