Skip to content

Instantly share code, notes, and snippets.

@CloneBoiii
Created March 14, 2019 07:30
Show Gist options
  • Save CloneBoiii/ad832e6ae0eb46ed7ad281549ba1cc21 to your computer and use it in GitHub Desktop.
Save CloneBoiii/ad832e6ae0eb46ed7ad281549ba1cc21 to your computer and use it in GitHub Desktop.
files.cpp
#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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment