c++ - C++ 中的 ASCII 艺术

标签 c++ ascii-art

我正在尝试输入 ASCII art在 C++ 程序中,并通过手动打印每一行来实现,但结果与 ASCII 艺术完全不同。就像:

Enter image description here

出现这种情况是因为提示无法识别字符还是我没有正确操作?

这是我正在尝试做的 ASCII 艺术:

_____/\\\\\\\\\________/\\\\\\\\\\\__________/\\\\\\\\\__/\\\\\\\\\\\__/\\\\\\\\\\\_        
 ___/\\\\\\\\\\\\\____/\\\/////////\\\_____/\\\////////__\/////\\\///__\/////\\\///__       
  __/\\\/////////\\\__\//\\\______\///____/\\\/_______________\/\\\_________\/\\\_____      
   _\/\\\_______\/\\\___\////\\\__________/\\\_________________\/\\\_________\/\\\_____     
    _\/\\\\\\\\\\\\\\\______\////\\\______\/\\\_________________\/\\\_________\/\\\_____    
     _\/\\\/////////\\\_________\////\\\___\//\\\________________\/\\\_________\/\\\_____   
      _\/\\\_______\/\\\__/\\\______\//\\\___\///\\\______________\/\\\_________\/\\\_____  
       _\/\\\_______\/\\\_\///\\\\\\\\\\\/______\////\\\\\\\\\__/\\\\\\\\\\\__/\\\\\\\\\\\_ 
        _\///________\///____\///////////___________\/////////__\///////////__\///////////__

代码:

cout << "_____/\\\\\\\\\________/\\\\\\\\\\\__________/\\\\\\\\\__/\\\\\\\\\\\__/\\\\\\\\\\\_        \n";
cout << " ___/\\\\\\\\\\\\\____/\\\/////////\\\_____/\\\////////__\/////\\\///__\/////\\\///__       \n";
cout << "  __/\\\/////////\\\__\//\\\______\///____/\\\/_______________\/\\\_________\/\\\_____      \n";
cout << "  _\/\\\_______\/\\\___\////\\\__________/\\\_________________\/\\\_________\/\\\_____     \n";
cout << "    _\/\\\\\\\\\\\\\\\______\////\\\______\/\\\_________________\/\\\_________\/\\\_____    \n";
cout << "    _\/\\\/////////\\\_________\////\\\___\//\\\________________\/\\\_________\/\\\_____   \n";
cout << "      _\/\\\_______\/\\\__/\\\______\//\\\___\///\\\______________\/\\\_________\/\\\_____  \n";
cout << "       _\///________\///____\///////////___________\/////////__\///////////__\///////////__\n";

最佳答案

escape sequences被解释为单个特殊字符或其他字符,因此输出奇怪。例如,"\\" 表示 '\'

您可以使用原始字符串文字:

#include <iostream>

int main()
{
    std::cout << R"(
_____/\\\\\\\\\________/\\\\\\\\\\\__________/\\\\\\\\\__/\\\\\\\\\\\__/\\\\\\\\\\\_        
 ___/\\\\\\\\\\\\\____/\\\/////////\\\_____/\\\////////__\/////\\\///__\/////\\\///__       
  __/\\\/////////\\\__\//\\\______\///____/\\\/_______________\/\\\_________\/\\\_____      
   _\/\\\_______\/\\\___\////\\\__________/\\\_________________\/\\\_________\/\\\_____     
    _\/\\\\\\\\\\\\\\\______\////\\\______\/\\\_________________\/\\\_________\/\\\_____    
     _\/\\\/////////\\\_________\////\\\___\//\\\________________\/\\\_________\/\\\_____   
      _\/\\\_______\/\\\__/\\\______\//\\\___\///\\\______________\/\\\_________\/\\\_____  
       _\/\\\_______\/\\\_\///\\\\\\\\\\\/______\////\\\\\\\\\__/\\\\\\\\\\\__/\\\\\\\\\\\_ 
        _\///________\///____\///////////___________\/////////__\///////////__\///////////__        
)" << '\n';

    return 0;
}

live demo

关于c++ - C++ 中的 ASCII 艺术,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37765925/

相关文章:

c++ - QTableWidget 和 QLineEdit - 位置和文本内容

c++ - 如何在 map 的 map 上使用 map::find

c++ - "Fun"在代码中解释 ASCII 数字的 C++ 库 - 它叫什么? ( "Multi-Dimensional Analog Literals")

c++ - 打印心形,里面有文字

assembly - "program successfully executed"显示在我的程序显示的 ASCII 图形的中间

c# - 将数组操作从 C++ 重写为 C#

c++ - 如何检索 ISearchBoxInfo 接口(interface)?

c++ - 如何在 C++ 中跨实例调用方法

c++ - 帮助算法动态更新文本显示

python - Python 中的文本到 ASCII 艺术生成器