Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ BinaryReader and BinaryWriter

Tags:

c++

I need to write an array of int to an output file as binary and also read the binary data as int in the programme in C++ Linux, something like the BinaryReader and BinaryWriter in C#. How could I do that?

Thanks

like image 412
Ashley Avatar asked May 23 '26 22:05

Ashley


1 Answers

Barring some outstanding reason to do otherwise, you'd typically use std::ostream::write and std::istream::read. Since you're producing a binary stream, you'll also typically want to specify std::ios::binary when you open the file.

like image 66
Jerry Coffin Avatar answered May 26 '26 11:05

Jerry Coffin