From 112a0d344da9e66d20ee9ab5d488e59c5d52e6ad Mon Sep 17 00:00:00 2001 From: Angeld55 Date: Thu, 9 Apr 2020 18:09:42 +0300 Subject: added new examples --- Binary_files/SaveStructsToBinaryFile(as array).cpp | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Binary_files/SaveStructsToBinaryFile(as array).cpp (limited to 'Binary_files/SaveStructsToBinaryFile(as array).cpp') diff --git a/Binary_files/SaveStructsToBinaryFile(as array).cpp b/Binary_files/SaveStructsToBinaryFile(as array).cpp new file mode 100644 index 0000000..146a93c --- /dev/null +++ b/Binary_files/SaveStructsToBinaryFile(as array).cpp @@ -0,0 +1,37 @@ +#include +#include +using namespace std; + +struct test +{ + char ch; + int num; +}; + +int main() +{ + + test arr[] = { { 'a', 4 }, { 'b', 5 }, { 'c', 6 } }; + + ofstream outF("Structs.bat", ios::binary); + + if (!outF.is_open()) + { + cout << "Error while opening file" << endl; + return 1; + } + + outF.write((const char*)&arr, sizeof(arr)); + //можем директно да запазим масива във файла. Резултатът ще същия като от SaveStructToBinaryFile.cpp + + + if (!outF.good()) + { + cout << "Error occurred while writing the file"; + return 1; + } + + outF.close(); + + return 0; +} \ No newline at end of file -- cgit v1.3.1-23-gd82d