print a filled square in console

荒凉一梦 提交于 2020-01-04 02:53:20

问题


I need to print a filled square in Linux terminal using my C++ program (1cm x 1cm size). I tried to use ASCII 254 (■), but in terminal it print as garbage character. I'm not sure how to print extended ASCII character using c++. Here are two methods I have tried to print extended ASCII. but not succeed.

First method

for(int i=128; i< 255; i++ )
{
 std::cout << static_cast<char>(i) << std::endl;
}

Second method

unsigned char temp = 'A'
for(int i=65; i< 255; i++ )
{
 std::cout << temp++ << std::endl;
 std::wcout << temp << std::endl;
}

Any suggestion or alternative Idea?


回答1:


Try using the unicode cout << "\u25A0";

http://www.fileformat.info/info/unicode/category/So/list.htm




回答2:


Or try just:

std::cout << (char)254u;



回答3:


Try this :

char t = -2;
cout << t;


来源:https://stackoverflow.com/questions/26438222/print-a-filled-square-in-console

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