Advertisement
MeehoweCK

Untitled

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