Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <fstream>
  4. #include <string>
  5. #include <cstdlib>
  6. #include <windows.h>
  7. #include "locale.h"
  8. using namespace std;
  9. #define use_CRT_SECURE_NO_WARNINGS;
  10.  
  11. int main()
  12. {
  13. setlocale(LC_ALL, "Russian");
  14.  
  15. SetConsoleCP(1251);
  16. SetConsoleOutputCP(1251);
  17. FILE *text;
  18. text = fopen("text.txt", "a+");
  19.  
  20. int c = 0; //счётчик искомых слов
  21. string word;
  22. cin >> word; //искомое слово
  23.  
  24. if (!text) cout << "Ошибка открытия файла для чтения!" << endl;
  25. else
  26. {
  27. string temp;
  28. while (text >> temp) //читается словo
  29. {
  30. cout << temp << ' ';
  31. if (temp == word)
  32. c++;
  33. //если считано предложение
  34. if (*(temp.end() - 1) == '.' || *(temp.end() - 1) == '!' || *(temp.end() - 1) == '?')
  35. {
  36. cout << endl << "c = " << c << endl;
  37. c = 0; //обнуление счётчика слов
  38. }
  39. }
  40. }
  41. system("pause");
  42. return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement