Create A File Using C Programming

Posted on by
Give More Feedback

Write a C program to write all the members of an array of structures to a file using fwrite(). Wolfenstein 3d Game Windows 7. Read the array from the file and display on the screen.

Here are examples for both native and managed C++: Assuming you are happy with a native solution the following works just fine: fstream *fs =new fstream(filename,ios::out ios::binary); fs->write('ghgh', 4); fs->close(); delete fs; // Need delete fs to avoid memory leak However, I would not use dynamic memory for the fstream object (i.e. The new statement and points). Here is the new version: fstream fs(filename,ios::out ios::binary); fs.write('ghgh', 4); fs.close(); EDIT, the question was edited to request a native solution (originally it was unclear), but I will leave this answer as it may be of use to someone If you are looking for a C++CLI option (for managed code), I recommend using StreamWriter instead of FileStream. StreamWriter will allow you work with Managed Strings. Note that delete will call the Dispose method on the IDisposable interface and the Garbage Collected will release the memory eventually: StreamWriter ^fs = gcnew StreamWriter(gcnew String(filename)); fs->Write((gcnew String('ghgh'))); fs->Close(); delete fs.