C++输出wchar_t问题

来源:百度知道 编辑:UC知道 时间:2024/09/21 20:21:02
我是在VS2008下面编译的,以下是代码:

#include <iostream>
#include <cwctype>
using namespace std;

int main(){
wchar_t c='你';
if('你'==c)cout<<"Yes"<<endl;;
wcout<<c<<endl;
wchar_t b='a';
wcout<<b<<endl;
return 0;
}

不知道为什么,运行后只有Yes被打印出来,而宽字符却没有。这是为什么?怎么解决?
那输入呢?也一样吗?有长字符型的字符串吗?

呃。。。首先宽字符和宽字符串常量前要加L,例如L'A'
然后中文的话,要设置区域使用wcout.imbue(locale("chs"));
给个简单的示例
#include <iostream>
#include <cwctype>
using namespace std;

int main()
{
wchar_t c=L'你';
wcout.imbue(locale("chs"));
wcout<<c<<endl;
system("pause");
return 0;
}

字符串一样的前面加前缀L,输入一样的。。。建议找本手册查查才是学习的好方法。还可以用全局函数setlocale(LC_ALL,"Chinese-simplified");。

唉一个0分的题我都啰嗦这么多,我真是游手好闲啊,惭愧。

呃。。。首先宽字符和宽字符串常量前要加L,例如L'A'
然后中文的话,要设置区域使用wcout.imbue(locale("chs"));
给个简单的示例
#include <iostream>
#include <cwctype>
using namespace std;

int main()
{
wchar_t c=L'你';
wcout.imbue(locale("chs"));
wcout<<c<<endl;
system("pause");
return 0;
}

字符串一样的前面加前缀L,输入一样的。。。建议找本手册查查