Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

C++ primer iz knjige

[es] :: C/C++ programiranje :: C++ primer iz knjige

[ Pregleda: 3940 | Odgovora: 1 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

bane

Član broj: 449
Poruke: 230
*.tv



Profil

icon C++ primer iz knjige16.02.2002. u 14:22 - pre 255 meseci
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




1000 zasto 1000 zato
 
Odgovor na temu

Dragi Tata
Malo ispod Kanade

Član broj: 1958
Poruke: 3906
..ndg-pm4-1.dialup.nethere.net



+6 Profil

icon Re: C++ primer iz knjige16.02.2002. u 18:37 - pre 255 meseci
Ti si ovo prijatelju pogrešno prekucao. Pazi ovo:

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);

Šta ex.insert radi tu, van svih funkcija?

A pazi tek ovaj biser:

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();
}

Pogledaj to malo bolje, pa se onda javi. To što si poslao SIGURNO ne piše u knjizi. Ako stvarno piše, bolje je baci.
 
Odgovor na temu

[es] :: C/C++ programiranje :: C++ primer iz knjige

[ Pregleda: 3940 | Odgovora: 1 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.