с++ в полученом файле посчитать количество одинаковых слов и вывести в консоль (файл с кириллицей)

#include <iostream>
#include <fstream>
#include <string>
#include <map>


//

#include <Windows.h>
#include <io.h>
#include <fcntl.h>

//

using namespace std;

/*class ConsoleCP
{
    int oldin;
    int oldout;

public:
    ConsoleCP(int cp)
    {
        oldin = GetConsoleCP();
        oldout = GetConsoleOutputCP();
        SetConsoleCP(cp);
        SetConsoleOutputCP(cp);
    }

    ~ConsoleCP()
    {
        SetConsoleCP(oldin);
        SetConsoleOutputCP(oldout);
    }
};*/

int wmain(int argc, wchar_t* argv[])
{
    //
    //_setmode(_fileno(stdout), _O_U16TEXT);
    //_setmode(_fileno(stdin), _O_U16TEXT);
    //_setmode(_fileno(stderr), _O_U16TEXT);
    //SetConsoleCP(1251);
    //SetConsoleOutputCP(1251);
    //
    //system("chcp 1251");
    //ConsoleCP cp(1251);

    wcout << "Enter file full path: ";
    wstring path;
    wcin >> path;


    wifstream file;
    file.open(path);


    if (!file.is_open())
    {
        wcout << "Error of opening file!" << endl;
    }
    else
    {
        map<wstring, int>result;
        wstring word;


        for (wifstream file(path); file >> word;)
        {

            wstring str;


            for (size_t i = 0; i < word.size(); i++)
            {
                if (iswalpha(word[i]) || word[i] == '-')
                {
                    str += word[i];
                }
            }
            word = str;

            ++result[word];
        }


        for (auto& pos : result)
        {
            wcout << pos.first << L": " << pos.second << endl;
        }
    }
    file.close();

    system("pause");

    return 0;
}

проблема заключается в том, что в консоли не корректно считывается кириллица, пробовал:

setlocale(LC_CTYPE, "");
SetConsoleCP(1251);
SetConsoleOutputCP(1251);

и другие кодировки вместо 1251; менять кодировки текстового файла, при ASII считывается, но не отображается буква і; и еще много чего; Помогите решить пожалуйста эту проблему. введите сюда описание изображения


Ответы (0 шт):