Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 9th, 2012  |  syntax: C++  |  size: 0.65 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include<iostream>
  2. #include<fstream>
  3. #include<string>
  4.  
  5. using namespace std;
  6.                                                                                 //program liczy ile razy dane slowo wystapilo w pliku o podanej nazwie
  7.                                                                                 //nazwa pliku oraz szukane slowo sa argumentami funkcji main
  8. int main(int argc, char *argv[]){
  9.  
  10.         try{
  11.                 ifstream plik;
  12.                 int licznik=0;
  13.  
  14.                 string nazwa=argv[1];
  15.                 string tekst;
  16.  
  17.                 plik.open(nazwa.c_str());
  18.  
  19.                 if(!plik.good())
  20.                         throw 1;
  21.                 while(!plik.eof()){
  22.                         plik>>tekst;
  23.                         if(argv[2]==tekst)
  24.                                 licznik++;
  25.                 }
  26.                 plik.close();
  27.                 cout<<"Szukane slowo wystepuje w pliku: "<<licznik<<" razy"<<endl;
  28.         }
  29.         catch(int){
  30.                 cout<<"brak pliku !"<<endl;
  31.         }
  32.  
  33.         return 0;
  34. }