Advertisement
35657

Untitled

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