8.2.2

来源:互联网 发布:伊斯兰 知乎 编辑:程序博客网 时间:2024/06/10 07:43

8.7

#include <fstream>#include <iostream>using namespace std;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;

8.8

#include <fstream>#include <iostream>using namespace std; 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;}
0 0
原创粉丝点击