fstream skipping characters without reading in bitmap

bitmap, c++, fstream

Solution

#include <fstream>
#include <iostream>
#include <string>

int main(int argc, char *argv[])
{
  const char *bitmap;
  const char *output = "s.txt";

  if (argc < 2)
    bitmap = "ben.bmp";
  else
    bitmap = argv[1];

  std::ifstream  in(bitmap, std::ios::in  | std::ios::binary);
  std::ofstream out(output, std::ios::out | std::ios::binary);
  char a;

  while (in.read(&a, 1) && out.write(&a, 1))
    ;

  if (!in.eof() && in.fail())
    std::cerr << "Error reading from " << bitmap << std::endl;

  if (!out)
    std::cerr << "Error writing to "   << output << std::endl;

  return 0;
}

Problem

I am trying to read a bmp file using fstream. However it skips the values between 08 and 0E (hex) for example, for values 42 4d 8a 16 0b 00 00 00 00 00 36 it reads 42 4d 8a 16 00 00 00 00 00 36 skipping 0b like it does not even exist in the document. What to do? code: ``` ifstream in; in.open("ben.bmp", ios::binary); unsigned char a='\0'; ofstream f("s.txt"); while(!in.eof()) { in>>a; f<<a; } ``` EDIT: using `in.read(a,1);` instead of `in>>a;` solves the reading problem but I need to write unsigned chars and `f.write(a,1);` does not accept unsigned chars. Anybody got a function to do the writing with unsigned chars?

Original source