//Файлы
//Вариант 7
//Версия 1.0
//2019
//Разработчик Голохвастов Егор
#include "pch.h"
#include <iostream>
#include <fstream>
#include <algorithm>
#include <iterator>
#include <string>
using namespace std;

bool validate(const string& _str) {
	return _str.size() <= 4;
}

int main(void) {
	setlocale(LC_ALL, "Russian");
	string path = "myFile.txt";
	ifstream fin;
	fin.open(path);
	if (!fin.is_open()) {
		cout << "Ошибка открытия файла!" << endl;
	}
	else {
		cout << "Файл открыт!" << endl << endl;
		char ch;
		cout << "Текст файла:" << endl << endl;
		while (fin.get(ch)) {
			cout << ch;
		}
		int Result = 0;
		ifstream inFile("myFile.txt", ios::in);
		Result = count_if(istream_iterator<string>(inFile), istream_iterator<string>(), validate);
		cout << endl << endl << "Количество слов, состоящих не более чем из 4 букв: " << Result << endl << endl;
	}
	fin.close();
	return EXIT_SUCCESS;
}