How can I use Russian language in std::wstring?

Viewed 216

I am making a input stream from file to a vector of wstrings. There might be russian charcters. If they were there, than after outputting the wstring to the console I am getting the empty line. If the charcters are from English alphabet or from punctuation marks, than every thing is alright. How to fix that?(I use linux)

#include <iostream>
#include <fstream>
#include <vector>
#include <string>

void read_text(std::vector<std::wstring> &words)
{
    std::wifstream input("input.txt");

    if( !(input.is_open()) )
    {
        std::cout << "File was not open!" << std::endl;
        throw -1;
    }

    std::wstring input_string;
    input >> input_string;

    while(input)
    {
        words.push_back(input_string);
        input >> input_string;
    }

    input.close();
}

int main()
{
    setlocale(LC_ALL, "ru_RU.UTF-8");

    std::vector<std::wstring> words;
    try             {   read_text(words);   }
    catch(int i)    {   return i;   }

    for (auto i : words)
    {
        std::wcout << i << std::endl;
    }

    return 0;
}
0 Answers
Related