-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
65 lines (54 loc) · 2.17 KB
/
main.cpp
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
//============================================================================
// Name : Address.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include "Person.h"
#include "Book.h"
int main() {
vector<Person> pBook; //members
string name,gender,number,queryMode,queryInf; //decleration
int count=0;
ifstream inRecord("record.txt"); //record.txt
ifstream inQuery("query.txt"); //query information
cout<<"pBookÈçÏÂ"<<endl;
for(string s;getline(inRecord,s);){
if(count==0){
count++;
}
else {
cout << s << endl; //output
istringstream isRecord(s);
isRecord >> name >> gender >> number;
Person person(name,gender,number);
pBook.push_back(person); //get the pBook
}
}
/*cout<<"pBookÈçÏÂ"<<endl;
for(Person pBook:pBook){ //see the pBook
cout<<pBook.getName()<<" "<<pBook.getGender()<<" "<<pBook.getNumber()<<endl;
}
*/
for (string s; getline(inQuery, s);) {
istringstream isQuery(s);
isQuery>> queryMode >> queryInf; //get query information
}
cout<<"Query information"<<queryMode<<queryInf<<endl;
Book book(pBook,queryMode,queryInf);
vector<Person> resultBook; //Query
resultBook=book.getMembers(); //get query results
cout<<"results"<<endl;
for(Person resultBook:resultBook){ //see ruslut book
cout<<resultBook.getName()<<" "<<resultBook.getGender()<<" "<<resultBook.getNumber()<<endl;
}
ofstream fout("result.txt"); //go into the file
for(Person resultBook:resultBook){
Person temp=resultBook;
fout<<temp.getName()<<" "<<temp.getGender()<<" "<<temp.getNumber()<<endl;
}
cout<<"go into the file successfully"<<endl;
fout.close();
return 0;
}