在Visual C ++中显示日语字符 [英] Displaying japanese characters in visual c++

查看:101
本文介绍了在Visual C ++中显示日语字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里有没有人知道如何在可视化c ++中使用日语字符?

Does anyone here have an idea how to work with japanese character in visual c++?

我正在尝试在使用可视化c ++的控制台中显示日语名称。 / p>

I'm trying to display a Japanese name in console with visual c++.

#include "stdafx.h"
#include <string>
#include <iostream>

using namespace std;

int main()
{
   cout << "北島 美奈" << endl;

   return 0;
}

控制台中的输出:

?? ??
Press any key to continue ...

希望有人可以提供帮助。谢谢。

Hope someone can help. Thank you.

推荐答案

我已经在控制台上使用自己的代码UTF-8和EUC-KR(korean)进行了测试。

I've tested with my own code both UTF-8 and EUC-KR(korean) on a console window using a cmd.exe.

这是我的源代码。

#include <string>
#include <iostream>

#include <windows.h>

int main()
{
    int codepage = CP_ACP; //CP_ACP, CP_OEMCP
    int conv_codepage = CP_UTF8; //CP_UTF8
    char str[256];
    char str1[256];
    wchar_t tstr[256], tstr2[256];

    memset(str, 0x00, 256);
    memset(str1, 0x00, 256);
    memset(tstr, 0x00, 256);
    memset(tstr2, 0x00, 256);

    memcpy(str, " 北島 美奈", sizeof(str));

    int nLen = MultiByteToWideChar(codepage, 0, str, -1, 0, 0); 
    MultiByteToWideChar(codepage, 0, str, -1, tstr, nLen);

    int len = WideCharToMultiByte( conv_codepage, 0, tstr, -1, NULL, 0, 0, 0 ); 
    WideCharToMultiByte(conv_codepage, 0, tstr, -1, str1, len ,0 ,0);

    cout << "2... " << str1 << endl;

    return 0;
}

案例1 UTF-8:在控制台上的结果
输出是合理的,因为str1变量是utf-8字符串。
我在utf-8控制台窗口上有正确的utf-8。

case 1 UTF-8: the result on a console The output is reasonable because the str1 variable is an utf-8 string. I've got a correct utf-8 on a utf-8 console window.

情况2 EUC-KR:控制台上的结果
我认为这种情况也可以接受带有utf-8字符串的utf-8字符串。

case 2 EUC-KR: the result on a console I think this case is also acceptable utf-8 string with a utf-8 string.

然后按如下所示更改代码

Then changing the code as follows

cout << "2... " << str << endl;

cout << "2... " << str1 << endl;

案例1 UTF-8:控制台上的结果
我认为这是可以接受的我是utf-8控制台上的Unicode字符串。

case 1 UTF-8: the result on a console I think this is okey to me for an unicode string on a utf-8 console.

情况1 EUC-KR:在控制台上的结果

case 1 EUC-KR: the result on a console

在euc-kr代码页中,它仍然是正确的unicode字符串。

It is still correct unicode string in a euc-kr codepage.

这篇关于在Visual C ++中显示日语字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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