Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <cstdlib>
- #include <windows.h>
- #include "locale.h"
- using namespace std;
- #define use_CRT_SECURE_NO_WARNINGS;
- int main()
- {
- setlocale(LC_ALL, "Russian");
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- FILE *text;
- text = fopen("text.txt", "a+");
- int c = 0; //счётчик искомых слов
- string word;
- cin >> word; //искомое слово
- if (!text) cout << "Ошибка открытия файла для чтения!" << endl;
- else
- {
- string temp;
- while (text >> temp) //читается словo
- {
- cout << temp << ' ';
- if (temp == word)
- c++;
- //если считано предложение
- if (*(temp.end() - 1) == '.' || *(temp.end() - 1) == '!' || *(temp.end() - 1) == '?')
- {
- cout << endl << "c = " << c << endl;
- c = 0; //обнуление счётчика слов
- }
- }
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement