When using std::istringstream
to read gray pixel values from a file (0-255), I notice a strange behavior and I can't understand what is happening.
To conserve memory, I want to read these values into unsigned chars (since they have the same 0-255 range). However, there appears to be some sort of casting/truncation going on.
Input file:
194
194
155
155
124
194
Here is my code:
getline(fp, line);
unsigned char temp;
istringstream iss(line);
iss >> temp;
When the value in the file is 194
, for instance, the integer value for temp is 49
...
What type of casting is going on?