Advertisement
MeehoweCK

Untitled

May 6th, 2024
661
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.47 KB | None | 0 0
  1. #include <fstream>
  2. #include <iostream>
  3.  
  4. int main() {
  5.     std::string slowo, temps;
  6.     std::cout << "Wpisz szukane slowo: ";
  7.     std::cin >> slowo;
  8.     auto licznik{ 0 };
  9.     std::ifstream hamlet{ "hamlet.txt" };
  10.     if (hamlet.fail()) {
  11.         std::cout << "BLAD! Plik nie zostal znaleziony!\n";
  12.         return 0;
  13.     }
  14.     while (hamlet >> temps) {
  15.         if (temps == slowo) {
  16.             ++licznik;
  17.         }
  18.     }
  19.     hamlet.close();
  20.     std::cout << "Slowo zostalo znalezione " << licznik << " razy.\n";
  21.     return 0;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement