
Untitled
By: a guest on
Aug 9th, 2012 | syntax:
C++ | size: 0.65 KB | hits: 12 | expires: Never
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
//program liczy ile razy dane slowo wystapilo w pliku o podanej nazwie
//nazwa pliku oraz szukane slowo sa argumentami funkcji main
int main(int argc, char *argv[]){
try{
ifstream plik;
int licznik=0;
string nazwa=argv[1];
string tekst;
plik.open(nazwa.c_str());
if(!plik.good())
throw 1;
while(!plik.eof()){
plik>>tekst;
if(argv[2]==tekst)
licznik++;
}
plik.close();
cout<<"Szukane slowo wystepuje w pliku: "<<licznik<<" razy"<<endl;
}
catch(int){
cout<<"brak pliku !"<<endl;
}
return 0;
}