Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <string>
- #include <Windows.h>
- using namespace std;
- struct student {
- string last_name;
- string first_name;
- int number;
- };
- int main() {
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- ifstream fin;
- fin.open("file.txt");
- if (!fin.is_open()) {
- cout << "Ошибка открытия файла" << endl;
- }
- else {
- int count = 0;
- size_t position = 0;
- string word, user_word;
- cout << "Введите слово для поиска: ";
- getline(cin, user_word);
- while (!fin.eof()) {
- getline(fin, word);
- position = word.find(user_word);
- while (position != string::npos) {
- count++;
- position = word.find(user_word, position + 1);
- }
- position = 0;
- }
- cout << count;
- fin.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement