#include#include int main() { CFile file; if (file.Open(_T("example.txt"), CFile::modeCreate | CFile::modeWrite)) { CString text = _T("This is some text to write to the file."); file.Write((LPCTSTR)text, text.GetLength() * sizeof(TCHAR)); file.Close(); } return 0; }
#includeThis code creates a new file called "example.bin" in the current folder, and writes an array of floating-point values to it in binary format. In both examples, the CFile class is used from the MFC library to perform file input and output operations.#include int main() { CFile file; if (file.Open(_T("example.bin"), CFile::modeCreate | CFile::modeWrite | CFile::typeBinary)) { float data[] = {123.456f, 789.012f, 345.678f}; file.Write(data, sizeof(data)); file.Close(); } return 0; }