namgor
November 29th, 2000, 12:04 PM
in binary mode... How can I write data in binary mode in C++ ??? I am currently using the following, but doesn't seem to work : (might not be binary mode):
ofstream out ("pixel.dat");
for (int i = 0; i < frames; i++) {
// get the data put into "buf"
out << buf;
}
Thanks!!!
nikb
November 30th, 2000, 07:26 AM
Hello...
First of all, please post your messages in the appropriate forum. This is the "Bugs & Fixes" forum, and I don't believe your question qualifies as either.
Anyways, you fail to open the file in binary mode. You must specify "binary mode" explicitly.
The following code opens the file in binary mode:ofstream out("pixel.dat",ios::binary|ios::out);
if(!out.is_open())
{
cerr<<"Aiee!! Failed to open the file!"<<endl;
return;
}
// I do not know what kind of variable "buf"
// is, but I will use the "write" member of
// the ofstream class, to write the binary
// data out... "bufsz" is an int that specifies
// the size of the data in the "buf" variable.
for(int i=0;i<frames;i++) // write the data
out.write(buf,bufsz);
// Write anything else you may want to here
// and close the stream
out.close();
I hope this helped,
-n