Advertisement
35657

Untitled

Apr 20th, 2024
549
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.98 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4. #include <string>
  5. #include <Windows.h>
  6.  
  7. using namespace std;
  8.  
  9. struct student {
  10.     string last_name;
  11.     string first_name;
  12.     int number;
  13. };
  14.  
  15. int main() {
  16.    
  17.     SetConsoleCP(1251);
  18.     SetConsoleOutputCP(1251);
  19.  
  20.     ifstream fin;
  21.     fin.open("file.txt");
  22.  
  23.     if (!fin.is_open()) {
  24.         cout << "Ошибка открытия файла" << endl;
  25.     }
  26.     else {
  27.         int count = 0;
  28.         size_t position = 0;
  29.         string word, user_word;
  30.         cout << "Введите слово для поиска: ";
  31.         getline(cin, user_word);
  32.  
  33.         while (!fin.eof()) {
  34.             getline(fin, word);
  35.             position = word.find(user_word);
  36.             while (position != string::npos) {
  37.                 count++;
  38.                 position = word.find(user_word, position + 1);
  39.             }
  40.             position = 0;
  41.         }
  42.         cout << count;
  43.         fin.close();
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement