问题描述
我尝试将句子从utf-8编码转换为FreeBSD中的CP1251(在Windows中工作正常)。从utf-8到德语ISO8859-1的转换也可以在FreeBSD中使用,但不能转换为任何俄语编码。这是代码:
#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;
}
在我的计算机上,它成功创建了语言环境,但是所有俄语符号都变为#
(默认)。
任何想法都会受到赞赏。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)