Advertisement
TheDuliX_

Untitled

Oct 4th, 2021
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 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. brojac++;
  20. } else {
  21. pronadjeno = false;
  22.  
  23.  
  24. }
  25. }
  26. }
  27. if (pronadjeno == true) {
  28. cout << "Rec je pronadjena " << brojac << " puta.";
  29. } else {
  30. cout << "Rec nije pronadjena";
  31. }
  32.  
  33. }
  34.  
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement