cout/wcout 输出中文问题

本文介绍了解决在读取注册表的小程序中遇到的中文字符显示问题及wcout阻塞的方法,通过设置locale为chs来实现中文字符的正确显示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在写一的读取注册表的小程序的时,发现中文字符不能显示,并导致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 

转载于:https://www.cnblogs.com/lvzaina/archive/2013/04/01/2993282.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值