Wide character output result [closed]

无人久伴 提交于 2019-12-20 07:48:43

问题


Why do I get numbers as output result when using wchar_t?

#include <iostream>
using namespace std;
int main()
{
    wchar_t q;
    q = 'A';
    cout << q;
    q = 'B';
    cout << q;
    q = 'C';
    cout << q;
    return 0;
}

回答1:


The displayed 'numbers' are the value of the character. That's the reason you get 'numbers'. If you want to display the characters you can use wcout




回答2:


std::cout is a basic_iostream<char>. There is no operator<< overload for wchar_t for basic_iostream<char>. When you output wchar_t objects they must be converted to some type for which there is an operator<< overload. The selected conversion is to an integral type other than char and so the integral value is shown instead of the represented character.



来源:https://stackoverflow.com/questions/13781948/wide-character-output-result

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!