简体   繁体   English

C ++日语字符命令行输出

[英]c++ Japanese characters command line output

I am having problems to print Japanese characters on my command line (osx) with c++. 我在使用c ++在命令行(osx)上打印日语字符时遇到问题。

I would be happy to see any character printed correctly on my command line, but I dont get what my problem is. 我很乐意在命令行上正确打印任何字符,但是我不明白我的问题是什么。 Nothing is printed, not even a wrong character nor any error occurs. 没有打印任何内容,甚至没有错误的字符,也没有发生任何错误。 My characters are just swallowed. 我的角色被吞下了。 What am I doing wrong here? 我在这里做错了什么?

 #include <string>
#include <clocale>
#include<iostream>

int main(int argc, char** args){

    std::setlocale(LC_ALL,"");
    wchar_t c=L'あ';
    std::wcout<<c;

    std::wstring s = L"あ";
    std::wcout<<s;

    return 0;
}

You probably don't need the line: 您可能不需要以下行:

std::setlocale(LC_ALL, "");

That's used for things like date and time formats. 这用于日期和时间格式之类的东西。

Instead, imbue the output stream with a properly initialized locale object. 而是使用正确初始化的locale对象对输出流进行赋值。

std::wcout.imbue(std::locale("ja_jp.utf-8"));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM