gpt4 book ai didi

c++ - 在控制台中打印一个填充的正方形

转载 作者:IT王子 更新时间:2023-10-29 00:57:39 25 4
gpt4 key购买 nike

我需要使用我的 C++ 程序在 Linux 终端中打印一个填充的正方形(1cm x 1cm 大小)。我尝试使用 ASCII 254 (■),但在终端中它打印为垃圾字符。我不确定如何使用 C++ 打印扩展的 ASCII 字符。这是我尝试打印扩展 ASCII 的两种方法。但没有成功。

第一种方法

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;
}

任何建议或替代想法?

最佳答案

尝试使用 unicode cout << "\u25A0";

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

关于c++ - 在控制台中打印一个填充的正方形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26438222/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com