[ bane @ 16.02.2002. 14:22 ] @
Radi se o primjeru iz knjige. Inace sve izgleda uredu ali ... *********************************************************************************************************************** #include<map> #include<set> #include<string> #include<iostream> #include<fstream> #include<stdio.h> using namespace std; void initialize_exclusion_set(set<string>&); void process_file(map<string,int>&, const set<string>&, ifstream&); void user_query(const map<string,int>&); void display_word_count(const map<string,int>&, ofstream&); int main() { ifstream ifile("C:\\My Documents\\column.txt"); ofstream ofile("C:\\My Documents\\column.map"); if(!ifile||!ofile) { cerr<<"Datoteka ne moze da se otvori-- predajem se!\n"; return -1; } set<string> exclude_set; initialize_exclusion_set(exclude_set); map<string,int> word_count; process_file(word_count, exclude_set,ifile), user_query(word_count); display_word_count(word_count, ofile); getchar(); } void initialize_exclusion_set(set<string> &exs) { static string _excluded_words[25]={ "the", "and", "but", "that", "then", "are", "been", "can", "a", "could", "did", "for", "of", "had", "have", "him", "his", "her", "its", "is", "were", "which", "when", "with", "would" }; exs.insert(_excluded_words, _excluded_words+25); void process_file(map<string,int> &word_count, const set<string &excluded_set, ifstream &ifile) { string word; while(ifile>>word) { if(exclude_set.count(word)) continue; word_count[word]++; } } void user_query(const map<string,int> &word_map) { string search_word; cout<<"Upisite rijec koja sadrzi: q za prekid"; while(search_word.size() && search_word!="q") { map<string,int>::const_iterator it; if((it=word_map.find(search_word)!=word_map.end()) cout<<"Naden!" <<it->first <<"Pojavljuje se " <<it->second <<"puta.\n"; else cout<<search_word <<"nije pronaden u tekstu.\n"; cout<<"\nJos jednom? (q za prekid)"; cin>>search_word; } } void display_word_count(const map<string,int> &word_map, ofstream &os); { map<string,int>::const_iterator iter=word_map.begin(), end_it=word_map.end(); while(iter!=end_it) { os<<iter->first <<" ( " <<iter->second<<" ) " <<endl; } os<<endl; } ************************************************************************************************************************ Info :Building... Info :Compiling C:\My Documents\c primjeri\textudat\textudat.cpp Warn : tree.h(236,3):Functions containing while are not expanded inline Warn : tree.h(241,3):Functions containing while are not expanded inline Warn : tree.h(272,3):Functions containing while are not expanded inline Warn : tree.h(300,3):Functions containing while are not expanded inline Warn : tree.h(349,3):Functions containing while are not expanded inline Warn : tree.h(377,3):Functions containing while are not expanded inline Warn : SET.h(137,3):Functions containing while are not expanded inline Warn : SET.h(142,3):Functions containing while are not expanded inline Warn : SET.h(205,3):Functions containing while are not expanded inline Warn : SET.h(209,3):Functions containing while are not expanded inline Warn : SET.h(304,3):Functions containing while are not expanded inline Warn : SET.h(309,3):Functions containing while are not expanded inline Warn : SET.h(354,3):Functions containing while are not expanded inline Warn : SET.h(358,3):Functions containing while are not expanded inline Warn : string.h(549,3):Functions containing for are not expanded inline Warn : string.h(557,3):Functions containing while are not expanded inline Warn : string.h(563,3):Functions containing for are not expanded inline Warn : string.h(575,3):Functions containing for are not expanded inline Warn : string.cc(686,32):Comparing signed and unsigned values Warn : string.cc(658,22):Cannot create pre-compiled header: code in header Error: textudat.cpp(19,12):Too few arguments in template class name 'set' Error: textudat.cpp(20,26):Call to undefined function 'initialize_exclusion_set' Error: textudat.cpp(20,38):Undefined symbol 'exclude_set' Error: textudat.cpp(21,16):Too few arguments in template class name 'map' Error: textudat.cpp(22,14):Call to undefined function 'process_file' Error: textudat.cpp(22,25):Undefined symbol 'word_count' Warn : textudat.cpp(22,44):Structure passed by value Error: textudat.cpp(23,12):Call to undefined function 'user_query' Error: textudat.cpp(24,20):Call to undefined function 'display_word_count' Warn : textudat.cpp(24,38):Structure passed by value Error: textudat.cpp(28,42):Too few arguments in template class name 'set' Warn : textudat.cpp(28,42):Style of function definition is now obsolete Error: textudat.cpp(28,44):) expected |