题目:重写7.1.1节的书店程序(P229),从一个文件中读取交易记录。将文件名作为一个参数传递给main。
#include <iostream>
#include <fstream>
#include "test.h"
using namespace std; int main(int argc, char** argv)
{
ifstream input(argv[]);
Sales_data total;
if (read(input, total)) {
Sales_data trans;
while (read(input, trans)) {
if (total.isbn() == trans.isbn()) {
total.combine(trans);
}
else {
print(cout, total) << endl;
total = trans;
}
}
print(cout, total) << endl;
}
else {
cerr << "No data?!" << endl;
}
return ;
}