Does this code work universaly, or is it just my system?

ぐ巨炮叔叔 提交于 2019-12-04 05:19:26

问题


#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;
}

回答1:


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.




回答2:


Won't work in an embedded system without a file system.

Or without that locale installed, of course.



来源:https://stackoverflow.com/questions/4324385/does-this-code-work-universaly-or-is-it-just-my-system

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!