write binary file

I use c-style command to write a binary file before. And now I would like to transfer to c++ style.
C-Style:
1
2
3
float f;
f1 = fopen(fn.c_str(),"wb");
fwrite(&f, sizeof(float),1,f1);

Can anybody show me how to transfer this to ofstream *out?
1
2
3
float f;
ofstream out_file(filename, ios_base::binary);
out_file << f;
That's it? Do we need to tell the chunk size to the program?
Last edited on
http://www.cplusplus.com/reference/iostream/fstream/
http://www.cplusplus.com/doc/tutorial/files/
1
2
3
4
float f=3.14587;
ofstream fl;
fl.open(fn.c_str(), ios::binary);
fl.write(reinterpret_cast<char*>(&f),sizeof(float));


Topic archived. No new replies allowed.