I am trying to read a bitmap ("sample.bmp") with fstream in C++. Every char of the file should be printed as a decimal and hexadecimal number. But the problem is, that at the 60th character or so the decimal numbers become negative. This is the code snippet I use:
//edit: code fixed
void bitmap::printHeader(std::string filename){
std::ifstream bmpFile;
std::vector<char> line;
util func;
bmpFile.open(filename, std::ios::binary | std::ios::in);
bmpFile.seekg(0, std::ios::end);
std::streampos length = bmpFile.tellg();
bmpFile.seekg(0, std::ios::beg);
line.resize(length);
bmpFile.read(&line[0], length);
for (int i = 0; i < line.size(); i++){
std::cout << (int)(UINT8)line[i] << std::endl;
func.dec2hex((int)(UINT8)line[i]);
}
bmpFile.close();
}
The first 60 characters are converted right. After that I get numbers from 0 to -255 which are not representing the right chararcter.