-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileProcess.cpp
More file actions
99 lines (88 loc) · 2 KB
/
FileProcess.cpp
File metadata and controls
99 lines (88 loc) · 2 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include "FileProcess.h"
//保存person
void person_file_save(vector<Person> &persons)
{
ofstream person_file("Person.txt");
if (person_file.is_open())
{
for (Person temp_person:persons)
{
temp_person.save(person_file);
}
}
else
{
cout << "Person.txt打开失败" << endl;
}
person_file.close();
}
//读取person
void person_file_read(vector<Person>& persons)
{
ifstream person_file("Person.txt");
if (person_file.is_open())
{
while (!person_file.eof())
{
InitPersonStruct person_list;
//person_list.ID = -1;
Person temp_person(person_list);
temp_person.read(person_file);
if (temp_person.ID >=0)
{
persons.push_back(temp_person);
}
}
}
else
{
cout << "Person.txt打开失败" << endl;
}
person_file.close();
}
//保存book
void book_file_save(vector<Book>& books)
{
ofstream book_file("Book.txt");
if (book_file.is_open())
{
for (Book temp_book : books)
{
temp_book.save(book_file);
}
}
else
{
cout << "Book.txt打开失败" << endl;
}
book_file.close();
}
void book_file_read(vector<Book>& books)
{
ifstream book_file("Book.txt");
if (book_file.is_open())
{
while (!book_file.eof())
{
InitBookStruct book_list;
book_list.ID = -1;
book_list.Author = { };
book_list.BorrowStatus = 1;
book_list.Press = "无";
book_list.Price = 0;
book_list.Status = 0;
book_list.Title = "无";
Book temp_book(book_list);
temp_book.read(book_file);
if (temp_book.ID >= 0)//判断是否从文件中正确读取
{
books.push_back(temp_book);
}
}
}
else
{
cout << "Book.txt打开失败" << endl;
}
book_file.close();
}