-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfileFunction.cpp
More file actions
60 lines (45 loc) · 979 Bytes
/
Copy pathfileFunction.cpp
File metadata and controls
60 lines (45 loc) · 979 Bytes
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
#include"fileOperate.h"
#include"main.h"
#include<fstream>
#include<iostream>
using namespace std;
void writeFile() {
fstream file;
file.open("info_merchandise.txt",ios::out|ios::trunc);
if (!file) {
printShortDash();
cout << "打开文件失败,请确保文件路径正确!!";
printShortDash();
cout << endl;
}
Merchandise *ptr = NULL;
ptr = ListOfGoods.getHeader();
while (ptr->next!=NULL) {
file << *(ptr->next);
ptr = ptr->next;
};
file.close();
}
void readFile(){
fstream file;
file.open("info_merchandise.txt", ios_base::in);
if (!file) {
printShortDash();
cout << "打开文件失败,请确保文件路径正确!!";
printShortDash();
cout << endl;
}
//Merchandise *ptr = NULL;
//ptr = ListOfGoods.getHeader();
Merchandise *backup=new Merchandise;
while(!file.eof()){
file >> *backup;
if (file.fail())
break;
ListOfGoods.insertData(backup);
backup->ModifyMERSTOCKS();
backup = new Merchandise;
};
delete backup;
file.close();
}