Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <vector>
- #include <windows.h> // для работы SetConsoleCP, SetConsoleOutputCP
- using namespace std;
- int main() {
- SetConsoleCP(1251); // установка кодовой страницы windows cp 1251 в поток ввода
- SetConsoleOutputCP(1251); // установка кодовой страницы windows cp 1251 в поток вывода
- ifstream fin;
- fin.open("C:/Users/PC/Desktop/file.txt");
- if (!fin.is_open()) {
- cout << "Ошибка открытия файла" << endl;
- }
- else {
- int count = 0;
- string word;
- string user_word;
- cout << "Введите строку для поиска: ";
- getline(cin, user_word);
- const int size = user_word.size();
- int k = 0;
- while (!fin.eof()) {
- getline(fin, word);
- for (int i = 0; i < word.size(); i++) {
- if (word[i] == user_word[0]) {
- for (int j = 0; j < min(size, word.size()); j++) {
- if (word[i] != user_word[j]) {
- k = 0;
- break;
- }
- k++;
- i++;
- }
- if (k == size) {
- count++;
- }
- k = 0;
- }
- }
- }
- fin.close();
- cout << "Количество повторений: " << count << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement