#include #include #include #include #include "date.h" #include "istream_iterator_date.h" using namespace std; int main(int argc, char **argv) { ifstream ifs("infile"); if (!ifs) { cerr << argv[0] << ": couldn't open infile\n"; return EXIT_FAILURE; } const istream_iterator_date end; cout << "The file contains " << distance(istream_iterator_date(ifs), end) << " dates,\n"; ifs.clear(ifs.rdstate() & ~ios_base::failbit); ifs.close(); if (!ifs) { cerr << argv[0] << ": couldn't close infile\n"; return EXIT_FAILURE; } ifs.open("infile"); if (!ifs) { cerr << argv[0] << ": couldn't reopen infile\n"; return EXIT_FAILURE; } const date crash(date::october, 29, 1929); //stock market const istream_iterator_date it = find(istream_iterator_date(ifs), end, crash); if (it == end) { cout << "not including " << crash << ".\n"; } else { cout << "including " << crash << ".\n"; } return EXIT_SUCCESS; }