MeehoweCK

Untitled

Jul 20th, 2018
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. string pobierz()
  7. {
  8.     string slowo_szukane;
  9.     cout << "podaj slowo" << endl;
  10.     cin >> slowo_szukane;
  11.     return slowo_szukane;
  12. }
  13.  
  14. int sprawdz(string slowo_szukane)
  15. {
  16.     ifstream plik;
  17.     plik.open("hamlet.txt");
  18.  
  19.     string slowo_aktualne;
  20.     int il_slowa = 0;
  21.     while (!plik.eof())
  22.     {
  23.         plik >> slowo_aktualne;
  24.         if(slowo_szukane==slowo_aktualne)
  25.             il_slowa++;
  26.     }
  27.     plik.close();
  28.     return il_slowa;
  29. }
  30.  
  31. int main()
  32. {
  33.     cout << sprawdz(pobierz()) << endl;
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment