forked from pezy/CppPrimer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex8_08.cpp
47 lines (42 loc) · 1.09 KB
/
ex8_08.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
//
// ex8_08.cpp
// Exercise 8.8
//
// Created by pezy on 11/28/14.
// Copyright (c) 2014 pezy. All rights reserved.
//
// @Brief Revise the program from the previous exercise to append its output
// to its given file.
// Run the program on the same output file at least twice to ensure
// that the data are preserved
// @See ex8_07.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], ofstream::app);
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;
}