在控制台中打印一个填充的正方形 [英] print a filled square in console
本文介绍了在控制台中打印一个填充的正方形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要使用C ++程序(1cm x 1cm大小)在Linux终端中打印一个实心方块.我尝试使用ASCII 254(■),但在终端中将其打印为垃圾字符.我不确定如何使用c ++打印扩展的ASCII字符.这是我尝试打印扩展ASCII的两种方法.但没有成功.
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.
第一种方法
for(int i=128; i< 255; i++ )
{
std::cout << static_cast<char>(i) << std::endl;
}
第二种方法
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?
推荐答案
尝试使用Unicode cout << "\u25A0";
Try using the unicode cout << "\u25A0";
http://www.fileformat.info/info/unicode/category/So/list.htm
这篇关于在控制台中打印一个填充的正方形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文