Original Post
OK, if you read my last post, sorry. It was garbled, and I had the information to hand, I just didn''t read it well enough.
Below is a snippet of code to read in a bitmap file via fstream.
I have tried this with different bitmaps, and it always fails.
1) The first int of the file should be 19778 (or "BM" in ASCII)
My code refuses to read it in as an integer, but I can read it in as char[2]. But why not as integer.
2) I cannot read in long data. All I end up with is the exception bits fail and badbit being set.
std::fstream fs;
fs.exceptions(std::ios::badbit|std::ios::failbit);
try
{
fs.open(fn.c_str(),std::ios::in|std::ios::binary);
fs.setf(std::ios_base::dec);
char buffer[2];
// int buffer2;
fs>>buffer[0] >> buffer[1];
//fs>>buffer2;
//Read in Header, Needs to be == 19778
printf("%s2\n",&buffer[0]);
//Read in the Rest of the Header Information
long numBuffer;
fs>>numBuffer;//bmp->FileData.bfSize;
// printf("%i\n",numBuffer);//bmp->FileData.bfSize);
}
catch(std::ios::failure e)
{
const int test = fs.exceptions();
if (test&std::ios_base::badbit)
printf ("BadBit Exception Thrown.\nType = %i\n",test);
if (test&std::ios_base::failbit)
printf ("failbit Exception Thrown.\nType = %i\n",test);
if (test&std::ios_base::eofbit)
printf ("eofbit Exception Thrown.\nType = %i\n",test);
}
fs.close();
Can anyone see what is wrong (using DJGPP)
Bp.