这个代码工作是普遍的,还是只是我的系统? [英] Does this code work universaly, or is it just my system?

查看:106
本文介绍了这个代码工作是普遍的,还是只是我的系统?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#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不是通用的。它甚至不确定与它类似的语言环境存在。

It's your system. Locale names are not part of the C++ standard, so "en_US.UTF-8" is not universally valid. It's not even certain that a locale similar to it exists.

这篇关于这个代码工作是普遍的,还是只是我的系统?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆