当前位置: 首页>>代码示例>>C++>>正文


C++ TextQuery::run_query方法代码示例

本文整理汇总了C++中TextQuery::run_query方法的典型用法代码示例。如果您正苦于以下问题:C++ TextQuery::run_query方法的具体用法?C++ TextQuery::run_query怎么用?C++ TextQuery::run_query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TextQuery的用法示例。


在下文中一共展示了TextQuery::run_query方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(int argc, char **argv)
{
    std::ifstream infile;

    if (2 > argc || !open_file(infile, argv[1]))
    {
        cerr << "No input file!" << endl;
        return EXIT_FAILURE;
    }

    TextQuery tq;
    tq.read_file(infile);

    while (true)
    {
        cout << "enter word to look for, or q to quit: ";
        string s;
        cin >> s;

        if (!cin || s == "q")
            break;

        set<TextQuery::line_no> locs = tq.run_query(s);
        print_results(locs, s, tq);
    }

    return EXIT_SUCCESS;
}
开发者ID:qh997,项目名称:CppLearning,代码行数:28,代码来源:word-statistics.cpp

示例2: main

int main(int argc, char **argv)
{
    // open the file from which user will query words
	ifstream infile;
	if (argc < 2 || !open_file(infile, argv[1])) {
		cerr << "No input file!" << endl;
		return EXIT_FAILURE;
	}
	TextQuery tq;
	tq.read_file(infile); // builds query map
	// iterate with the user: prompt for a word to find and print results
	// loop indefinitely; the loop exit is inside the while
	while (true) {
		cout << "enter word to look for,or q to quit" << endl;
		string s;
		cin >> s;
		// stop if hit eof on input or a 'q'is entered
		if (!cin || s == "q")
			break;
        	// get the set of line numbers on which this word appears
		set<TextQuery::line_no> locs = tq.run_query(s);
		// print count and all occurrences, if any
		print_results(locs, s, tq);
	}
	return 0;
}
开发者ID:jakejiangjn,项目名称:CppPrimer4Ed,代码行数:26,代码来源:querymain.cpp

示例3: compute

void EchoServer::compute(const std::string &word, const TcpConnectionPtr &conn, const TextQuery &tq)
{	
	if(word == "q")
		exit(0);

	typedef set<TextQuery::line_no> line_nums;
	line_nums locs = tq.run_query(word);
	line_nums::size_type size = locs.size();
	
	char ssize[128] = "";
	sprintf(ssize, "%d", size);

	string s;
	s = s + "\n" + word +  " occurs " + ssize + " "
		 + make_plural(size, "time", "s") + "\n";
	line_nums::const_iterator it = locs.begin();
	for ( ; it != locs.end(); ++it)
	{
		char sit[128] = "";
		sprintf(sit, "%d", (*it) + 1);

		s = s +  "\t(line " + sit + ") "
			 + tq.text_line(*it) + "\r\n";
	}
	s = s + "\nenter word to look for, or q to quit: ";
	conn->send(s);
}
开发者ID:souldong1591,项目名称:project,代码行数:27,代码来源:EchoServer.cpp

示例4: 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;
}
开发者ID:CurvaVita,项目名称:C--------C---Primer--,代码行数:57,代码来源:3ed_querymain.cpp

示例5: textquery_test

void textquery_test(ifstream &infile)
{
  TextQuery tq;
  tq.read_file(infile);
  while (true) 
  {
    cout << "enter word to look for,or q to quit: ";
    string s;
    cin >> s;
    if (!cin || s == "q") 
      break;
    set<TextQuery::line_no> locs = tq.run_query(s);
    print_result(locs,s,tq);
  }
}
开发者ID:cheetah0216,项目名称:CodeRepository,代码行数:15,代码来源:text_main.cpp

示例6: main

int main(int argc, char *argv[])
{
    TextQuery tq;
    ifstream is("luo.txt");
    tq.read_file(is);
    string str("luo");
    set<TextQuery::line_no> s_lno = tq.run_query(str);
    cout << str << " occurs " << s_lno.size() << " times" << endl;
    for(set<TextQuery::line_no>::iterator iter = s_lno.begin();
                                          iter != s_lno.end(); ++iter) {
        cout << "(line " << *iter << ") ";
        cout << tq.text_line(*iter) <<endl;
    }

    return 0;
}
开发者ID:KnowNo,项目名称:algorithms,代码行数:16,代码来源:chapter10_textquery.cpp

示例7: main

int main()
{
ifstream infile("dat");
if(!infile){
cerr << "can't open the file..." << endl;
exit(0);
}
TextQuery tq;
tq.read_file(infile);
while(true){
cout << "Input the word to look for,q to exit:"<< endl;
string s;
cin >> s;
if(!cin || s == "q")
  break;
set<TextQuery::line_no> locs = tq.run_query(s);
  print_results(locs,s,tq);
}
return 0;
}
开发者ID:swordcheng,项目名称:TextQuery,代码行数:20,代码来源:Main.cpp

示例8:

	set<line_no> 
		eval(const TextQuery & t) const {return t.run_query(query_word);}
开发者ID:peter517,项目名称:BookCode,代码行数:2,代码来源:Test_forever.cpp


注:本文中的TextQuery::run_query方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。