-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreator.cpp
More file actions
36 lines (34 loc) · 1.09 KB
/
Creator.cpp
File metadata and controls
36 lines (34 loc) · 1.09 KB
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
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
struct employee
{
int num; // èäåíòèôèêàöèîííûé íîìåð ñîòðóäíèêà
char name[10]; // èìÿ ñîòðóäíèêà
double hours; // êîëè÷åñòâî îòðàáîòàííûõ ÷àñîâ
};
int main() {
string BinName;
int NumberOfLines;
cout << "enter bin file name and number of employees \n";
getline(cin, BinName);
cin >> NumberOfLines;
cout << "enter data (id, name and number of hours) \n";
employee* E = new employee[NumberOfLines]; //employee array
ofstream outfile(BinName, ios::out | ios::binary); // Creating a bin file from console
if (!outfile) {
cerr << "file not open!" << endl;
return 1;
}
for (int i = 0; i < NumberOfLines; i++)
{
cin >> E[i].num >> E[i].name >> E[i].hours;
outfile.write((char*)&E[i], sizeof(E[i]));
/* outfile.write((char*)&E[i].num, sizeof(E[i].num));
outfile.write(E[i].name, sizeof(E[i].name));
outfile.write((char*)&E[i].hours, sizeof(E[i].hours));*/
}
outfile.close();
return 0;
}