#include "stdafx.h"
#include <string>
#include <iostream>
#include <locale>
#include <clocale>
using namespace std;
int main()
{
std::wstring str = L"ä";
wcout.imbue( std::locale("German") ); //imbue不能使字符正常
wcout << str ;
std::string str2 = "ä";
cout.imbue( std::locale("German") );
cout << str2 ;
std::locale::global( std::locale("German") ); //global可以使字符正常输出
wcout << str ;
cout << str2 ;
char* name = setlocale(LC_ALL,NULL); //查询全局locale名字
printf("%s",str2); //打印正常
//结论:cout,wcout的底层是使用C语言的函数做输出的。C语言的printf等函数依赖于全局locale
//因为imbue函数不影响全局locale,所以只imbue不能正常的输出文字
system("pause");
return 0;
}
imbue
最新推荐文章于 2024-07-08 10:20:12 发布