16

MS Visual Studio 2010/2012 でコンソール アプリケーションとしてコンパイルされ、Win7 で実行される次のコード スニペットを検討してください。

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


const std::wstring test = L"hello\xf021test!";

int _tmain(int argc, _TCHAR* argv[])
{
    std::wcout << test << std::endl;
    std::wcout << L"This doesn't print either" << std::endl;

    return 0;
}

最初の wcout ステートメントは "hello" を出力します ("hello?test!" のようなものではなく)。2 番目の wcout ステートメントは何も出力しません。

あたかも 0xf021 (および他の?) Unicode 文字が原因で wcout が失敗するかのようです。

この特定の Unicode 文字 0xf021 (UTF-16 としてエンコード) は、基本多言語面の「私用領域」の一部です。Windows コンソール アプリケーションは Unicode 文字を広範囲にサポートしていないことに気付きましたが、通常、特定のグリフのレンダリングがサポートされていなくても、各文字は少なくとも既定の文字 ("?" など) で表されます。

wcout ストリームがチョークする原因は何ですか? この状態になった後にリセットする方法はありますか?

4

2 に答える 2