本文整理汇总了C++中TextQuery::display_map方法的典型用法代码示例。如果您正苦于以下问题:C++ TextQuery::display_map方法的具体用法?C++ TextQuery::display_map怎么用?C++ TextQuery::display_map使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TextQuery
的用法示例。
在下文中一共展示了TextQuery::display_map方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char **argv)
{
if (argc != 2) {cerr << "No input file" << endl; return -2;}
// get a file to read from which user will query words
ifstream infile;
if (!open_file(infile, argv[1])) {
cerr << "No input file!" << endl;
return -1;
}
TextQuery tq;
tq.read_file(infile); // builds query map
// iterate with the user: prompt for a word to find and print results
string sought;
do {
cout << "enter a word against which to search the text.\n"
<< "to quit, enter a single character ==> ";
cin >> sought;
// stop if hit eof on input or single character entered
if (!cin || sought.size() < 2) break;
// find all the occurrences of the users requested string
vector<TextQuery::location> locs = tq.run_query(sought);
// report no matches
if (locs.empty()) {
cout << "\nSorry. There are no entries for "
<< sought << ".\nTry again." << endl;
continue;
}
// if the word was found, then print count and all occurrences
vector<TextQuery::location>::size_type size = locs.size();
cout << "\n" << sought << " occurs " << size
<< (size == 1 ? " time:" : " times:")
<< "\n" << endl;
// print each line in which the word appeared
vector<TextQuery::location>::iterator it = locs.begin();
while (it != locs.end()) {
cout << "\t(line: "
// don't confound user with text lines starting at 0
<< it->first + 1 << ", pos: " << it->second + 1 << ") "
<< tq.text_line(it->first) << endl;
++it;
}
} while (!sought.empty());
cout << "Ok, bye!" << endl;
// debugging aid -- look at the map that was built
tq.display_map();
return 0;
}