cout/wcout 输出中文问题

在写一的读取注册表的小程序的时,发现中文字符不能显示,并导致wcout阻塞(连后面的wcout都不输出了)

解决:

wcout.imbue(locale("chs"));
//cout.imbue(locale("chs"));

 API

locale imbue ( const locale& loc );
 

Imbue locale

Associates loc to the stream as the new locale object to be used with locale-sensitive operations.

Before that, all callback functions registered through register_callback member with imbue_event as its first parameter are called.

 

Parameters

loc
locale object to be imbued as the new locale for the stream.

 

Return value

The locale object associated with the stream before the call.

 

Example

// imbue example
#include <iostream>
#include <locale>
using namespace std;
  
int main()
{
  locale mylocale("");      // Construct locale object with the user's default preferences
  cout.imbue( mylocale );   // Imbue that locale
  cout << (double) 3.14159 << endl;
  return 0;
}

This code writes a floating point number using the user's prefered locale. For example, in a system configured with a Spanish locale as default, this should write the number using a comma decimal separator:

3,14159 
posted @ 2013-04-01 13:27  赤色  阅读(315)  评论(0编辑  收藏  举报
知识共享许可协议本博客作品采用知识共享署名-相同方式共享 3.0 未本地化版本许可协议进行许可。