I try to convert sentence from utf-8 encoding into CP1251 in FreeBSD (in Windows it works fine). Conversion from utf-8 to German ISO8859-1 also works in FreeBSD, but to any Russian encoding does not. Here is the code:
#include <iostream>
#include <locale>
#include <string>
#include <codecvt>
#include <vector>
int main(int argc, char* argv[]){
// std::string g = "A-Za-zÄÖÜßäöüß";
std::string g = "А-Яа-я";
// const char* enc = "de_DE.ISO8859-1";
const char* enc = "ru_RU.CP1251";
std::locale loc(enc);
std::cout << loc.name() << std::boolalpha << " has facet "
<< std::has_facet<std::ctype<wchar_t>>(loc) << '\n';
std::wstring_convert<std::codecvt_utf8<wchar_t>> wconv;
std::wstring wstr = wconv.from_bytes(g);
std::vector<char> buf(wstr.size());
std::use_facet<std::ctype<wchar_t>>(loc).narrow(wstr.data(), wstr.data()
+ wstr.size(), '#', buf.data());
for(auto s: buf) { std::cout << s << '\n'; }
return 1;
}
On my computer it creates locale successfully, but all Russian symbols become #
(default).
Any thoughts will be appreciated.