Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #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;
- }
Advertisement
Add Comment
Please, Sign In to add comment