-
Notifications
You must be signed in to change notification settings - Fork 33
/
12.27.cpp
41 lines (38 loc) · 854 Bytes
/
12.27.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
/*
* Exercise 12.27: The TextQuery and QueryResult classes use only capabilities
* that we have already covered. Without looking ahead, write your own versions
* of these classes.
*
* By Faisal Saadatmand
*
* Note: refer to TextQuery.h for the class' definitions
*
*/
#include <fstream>
#include <iostream>
#include "TextQuery.h"
void runQueries(std::ifstream &infile)
{
TextQuery tq(infile);
while (true) {
std::cout << "Enter word to look for, or q to quit: ";
std::string s;
if (!(std::cin >> s) || s == "q")
break;
print(std::cout, tq.query(s)) << std::endl;
}
}
int main(int argc, char **argv)
{
if (argc != 2) {
std::cerr << "Usage: " << *argv << " infile\n";
return -1;
}
std::ifstream file(*++argv);
if (!file) {
std::cerr << "could not open " << *argv << '\n';
return -1;
}
runQueries(file);
return 0;
}