imbue

来源:互联网 发布:亲宝宝软件下载 编辑:程序博客网 时间:2024/06/08 09:13
#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;} 

0 0