开发者

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

#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);
        w开发者_如何学Gocout << 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;
}


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.


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

Or without that locale installed, of course.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜