Create and save binary file with FileStream : FileStream « File Directory « Visual C++ .NET






Create and save binary file with FileStream

 

#include "stdafx.h"
using namespace System;
using namespace System::IO;

void main()
{
    FileStream ^fso = gcnew FileStream("file.dat", FileMode::Create,FileAccess::Write, FileShare::None);

    array<unsigned char>^ data = gcnew array<unsigned char> { 'T', 'h', 'i','\r', '\n' };

    for (int i = 0; i < data->Length-5; i += 5)
    {
        fso->Write(data, i, 5);
    }


    fso->Close();


}

   
  








Related examples in the same category

1.Get binary file length
2.Read binary file to an array
3.Rewind by setting the binary file reading position
4.Read byte from binary file