Advertisement
TheDuliX_

Untitled

Oct 4th, 2021
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. using namespace std;
  5. int main(){
  6. fstream fajl;
  7. string text;
  8. string rec;
  9. bool pronadjeno;
  10. int brojac = 0;
  11. fajl.open("fajl.txt");
  12. if (fajl.is_open()) {
  13. cout << "Unesite rec za pretragu: ";
  14. cin >> rec;
  15. while(getline(fajl, text)){
  16.  
  17. if (rec.find(text) != string::npos) {
  18. pronadjeno = true;
  19. }
  20. if (pronadjeno == true) {
  21. brojac++;
  22. }
  23. else {
  24. pronadjeno == false;
  25. }
  26. }
  27. }
  28. if (pronadjeno == true) {
  29. cout << "Rec je pronadjena " << brojac << " puta.";
  30. } else {
  31. cout << "Rec nije pronadjena";
  32. }
  33. }
  34.  
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement