I'm reading a file, byte to byte. After a while, apparently i read a byte with a negative code.
Here's the troublesome code segment (which is inside a loop)
1 2 3 4 5 6 7
|
// DATA TYPES
//i short;
//char buffer;
//fstream ifs;
ifs.read(&buffer,1);
i = (short) buffer;
cout << "Read byte with code: "<< i << endl;
| |
I need the
positive ascii code of the byte i've just read. How should I do that?
Last edited on
Try using an unsigned char.
Effectively, that solved the problem. Thanks!