#include #include #include #include #include #include #include #include #include #define і i using namespace std; int getRateWordByPattern(const string& word, const string& pattern) // пошук слова в словнику { int rate = 0; for (int i = 0; i < pattern.size(); ++i) rate += std::count(word.begin(), word.end(), pattern[i]); return rate; } list GetListInFile(string path) { list newListStr; ifstream ifs(path); list words{ istream_iterator(ifs), istream_iterator() }; for (auto word : words) { for (int i = 0; i < word.length(); i++) { if (word[i] == ',' || word[i] == '.' || word[i] == '!' || word[i] == '?') { word[i] = ' '; } } newListStr.push_back(word); } ifs.close(); return newListStr; } void main() { setlocale(0, ""); SetConsoleCP(1251); SetConsoleOutputCP(1251); string pattern = "прй hjuh\nf"; string path = "dictionary.txt"; string pathCheck = "text.txt"; ifstream f; f.open(path); if (!f.is_open()) return; int max_rate = 0; string res_word = "not found"; list l; string word, w; //while (f >> word) //{ // int rate = getRateWordByPattern(word, pattern); // if (rate > max_rate) // { // max_rate = rate; // res_word = word; // } //} //String str; string s; while (getline(f, s)) { //str.str //int rate = getRateWordByPattern(word, pattern); //if (max_rate != rate) { l.push_back(s); //} } f.close(); for (auto word : GetListInFile(pathCheck)) { cout << word << endl; } for (auto item : l) { //cout << item << "\n"; } //wcout << max_rate << endl; //cout << res_word << endl; //cout << w << endl; std::ofstream out("dictionary.txt", std::ios::ate); if (out.is_open()) { out << "привіт\nуяви\nпрощавай gh, j" << std::endl; } out.close(); std::string line; ifstream in("dictionary.txt"); // окрываем файл для чтения if (in.is_open()) { while (getline(in, line)) { //std::cout << line << std::endl; } } string ls; while (in >> line) { if (line == " ") { line += "\n"; } //l.push_back((line)); } for (auto item : l) { //cout << item << "\n"; } in.close(); string res; list lres; for (auto item : l) { res += item + " "; } }