Settings | Sign in | Sign up

The author has 2 posts.

【程序】使用WriteConsoleW函数在控制台中输出宽字符

Floor 1 巨大八爪鱼 3/1/16 16:07
#include <iostream>
#include <Windows.h>

// 使用此函数输出宽字符变量
// 普通字符串请直接用cout输出
inline void echo(HANDLE hOut, LPWSTR wstr)
{
    WriteConsoleW(hOut, wstr, wcslen(wstr), NULL, NULL);
}

void main()
{
    HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
    echo(hOut, L"abc简体中文");
    std::cout << std::endl;
    echo(hOut, L"田中さんにあげて下さい");
    std::cout << std::endl;
    echo(hOut, L"اللغة العربية"); // 这个无法显示。。。
    std::cout << std::endl;
    echo(hOut, L"¿Cómo estás?");
    std::cout << std::endl;
    system("pause");
}
Floor 2 巨大八爪鱼 3/1/16 16:08
运行结果:

Content converter:

Reply the post
Content:
User: You are currently anonymous.
Captcha:
Unclear? Try another one.