C++ Printing special ascii characters to the Windows console

允我心安 提交于 2019-12-07 07:30:30

Welcome to the pain of encoding :(

#include <iostream>
#include <windows>

int main() {
    SetConsoleCP(437);
    SetConsoleOutputCP(437);
    std::cout << (char)157 << "\n";
}

Generates:

The problem is that your source file is not in CP437 and therefore the character has a different value than the one you are trying to print (as you noted, in your source value is is 165 which is a different character in CP437).

https://en.wikipedia.org/wiki/Code_page_437

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