forked from Mooophy/Cpp-Primer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex8_07.cpp
45 lines (40 loc) · 1.01 KB
/
ex8_07.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
//
// ex8_07.cpp
// Exercise 8.7
//
// Created by pezy on 11/28/14.
//
// @Brief Revise the bookstore program from the previous section to write its output to a file.
// Pass the name of that file as a second argument to main.
// @See ex8_06.cpp
// @Run give a parameter: "../data/book.txt ../data/out.txt"
#include <fstream>
#include <iostream>
#include "../ch07/ex7_26.h"
using std::ifstream; using std::ofstream; using std::endl; using std::cerr;
int main(int argc, char **argv)
{
ifstream input(argv[1]);
ofstream output(argv[2]);
Sales_data total;
if (read(input, total))
{
Sales_data trans;
while (read(input, trans))
{
if (total.isbn() == trans.isbn())
total.combine(trans);
else
{
print(output, total) << endl;
total = trans;
}
}
print(output, total) << endl;
}
else
{
cerr << "No data?!" << endl;
}
return 0;
}