c++ - 此代码是否通用,还是仅适用于我的系统?

标签 c++ unicode utf-8 locale wofstream

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main()
{
        locale system("");
        locale::global(system);

        wcin.imbue(system);

        wstring data;
        getline(wcin,data);

        wcout.imbue(system);
        wcout << data << L" length=" << data.length() << endl;

        locale utfFile("en_US.UTF-8");
        wofstream file("my_utf_file.txt");
        file.imbue(utfFile);

        file << data;
        file << endl;

        file.close();

        return 0;
}

最佳答案

这是您的系统。语言环境名称不是 C++ 标准的一部分,因此 "en_US.UTF-8" 不是普遍有效的。甚至不确定是否存在与它相似的语言环境。

关于c++ - 此代码是否通用,还是仅适用于我的系统?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4324385/

相关文章:

c++ - 创建一个引用另一个 vector 的某些元素的 vector

ruby-on-rails-3 - 包含重音字符的名称的 ActiveRecord 查询失败

c++ - 在 sfml 中使用 UTF8

perl - 使用 Perl 玩转 Unicode

c++ - 尝试从 Octave 的独立程序示例编译示例代码,在第一行出现段错误

c# - 创建 native DLL

ruby - 防止 JSON pretty_generate 转义 Unicode

perl - 关于路径名编码的问题

c++ - 如何在 Windows 上安装 protobuf? (Win7x64/MinGW)

ruby - 将 Unicode 中的阿拉伯语和日语文本按字母顺序排列?