Ananya
Thu May 24 08:04:00 CDT 2007
Well, pixcount is the correct number, which is > 0.
However, the output file chars.dat was always only written once I exited the
method inside which I was doing the writing.
But saying file.close() also finishes the writing of the file.
Thanks a lot!
"Stefan Naewe" wrote:
> On 5/24/2007 1:07 PM, Ananya wrote:
> >> Ananya wrote:
> >>> Well, I was "googleing" for some code, and even though I asked for C++, it
> >>> seems I ended up with some C# code, which I cannot use.
> >>>
> >>> So I tried the following C++ code:
> >>> unsigned char *pixels = ...
> >>> char *charpixels = reinterpret_cast<char*>(pixels);
> >>> fstream file;
> >>> file.open("chars.dat", ios::out);
> >>> file.write(charpixels, count);
> >>>
> >>> Now the code compiled, but it doesn't seem to write the correct byte.
> >>> Does reinterpret_cast not work right?
> > I am using standard C++ and I am using VS2005.
> >
> > I tried
> >
> > file.open("chars.dat", ios::out | ios::binary);
> > file.write(charpixels, pixcount);
> >
> > but the chars.dat file only gets opened, it still does not get written, it
> > stays empty.
> >
> > Shouldn't this work with standard C++? How can I make it work?
>
> Is 'pixcount' > 0 ?
> Did you correctly end your program (not killing it with CTRL-C or
> anything else) ?
>
> Try to explicitly close the file (file.close() ) and check the size
> then.
>
> S.
> --
> Stefan Naewe stefan dot naewe at atlas-elektronik dot com
> Don't top-post
http://www.catb.org/~esr/jargon/html/T/top-post.html
> Plain text mails only, please
http://www.expita.com/nomime.html
>