How to save a byte type char array data to a file in c++?

Some people object to using <cstdio>, so it is worth mentioning how one might use <fstream>:

{
  std::ofstream file("myfile.bin", std::ios::binary);
  file.write(data, 100);
}

The four lines above could be combined into this single line:

std::ofstream("myfile.bin", std::ios::binary).write(data, 100);

No need to get complicated. Just use good old fwrite directly:

FILE* file = fopen( "myfile.bin", "wb" );
fwrite( array, 1, 100, file );

Based on the (little) information you've provided, one possibility would be to write the array to the file in binary format, such as:

std::ofstream out("somefile.bin", std::ios::binary);
out.write(array, sizeof(array));

Tags:

C++

Arrays