Тема: Фільтр рядків у файлі
Потрібно написати програму яка зчитує текст із файлу і виводить на екран тільки речення/рядки з вказаною кількістю слів.
Я шукав на інших форумах то знайшов схожу. Але там речення треба ввести самому при запуску щей тільки одне.
Ось вона:
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <algorithm>
#include <Windows.h>
using namespace std;
void pred(std::string& s)
{
    cout << " " << s;
}
int main(){
    SetConsoleCP(1251);
    SetConsoleOutputCP(1251);
    string s;
    int cnt = 0;
    int num=0;
    
    cout << "Введіть рядок: ";
    getline(cin, s);
    cout << "Введіть потрібну кількість слів: ";
    cin >> num;
    istringstream ist(s);
    vector<string> vec_word;
    while (ist >> s){
        vec_word.push_back(s);
        ++cnt;
    }
    cout << "Count words: " << cnt << endl;
    if (cnt == num) {
        for_each(vec_word.begin(), vec_word.end(), pred);
    }
    return 0;
}