blob: 146a93c3017b0ce53041660451d6f9d8309b2d82 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
#include <iostream>
#include <fstream>
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;
}
|