Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In C++, how to print ASCII art to the console?

Let's say you want to print out one of those great ASCII art images. How can you do that without cout each line individually?

like image 811
Mark Avatar asked Feb 02 '10 01:02

Mark


1 Answers

Adjacent string literals are concatenated, so you can do this:

cout << " _______________________ _______ _          _______         _______ _______  _______ _       _______         \n"
        "(  ____ \__   __/  ___  )  ____ \ \    /\  (  ___  )\     /|  ____ \  ____ )(  ____ \ \     (  ___  )\     /|\n"
        "| (    \/  ) (  | (   ) | (    \/  \  / /  | (   ) | )   ( | (    \/ (    )|| (    \/ (     | (   ) | )   ( |\n"
        "| (_____   | |  | (___) | |     |  (_/ /   | |   | | |   | | (__   | (____)|| (__   | |     | |   | | | _ | |\n"
        "(_____  )  | |  |  ___  | |     |   _ (    | |   | | (   ) )  __)  |     __)|  __)  | |     | |   | | |( )| |\n"
        "      ) |  | |  | (   ) | |     |  ( \ \   | |   | |\ \_/ /| (     | (\ (   | (     | |     | |   | | || || |\n"
        "/\____) |  | |  | )   ( | (____/\  /  \ \  | (___) | \   / | (____/\ ) \ \__| )     | (____/\ (___) | () () |\n"
        "\_______)  )_(  |/     \|_______/_/    \/  (_______)  \_/  (_______//   \__/|/      (_______/_______)_______)\n";

Or, more accurately, perhaps:

cout << "                              .::/-                                                                                                                                                             \n"
        "                              .+++/                                                                                                                                                             \n"
        "                   `.::`       /+++.                                                                                                                                                            \n"
        "                  -////.      :+++-                                                                                                                                                             \n"
        "                    .////-`    .+++/`                                                                                                                                                           \n"
        "                    `:///:`   `/++/.                                                                                                                                                            \n"
        "            ..`        -////.   -+++:                                                                                                                                                           \n"
        "           :+++:-`      .////:` ./++/`                                                                                                                                                          \n"
        "          `-/+++++/-.    `:////.`:++/.                                                                                                                                                          \n"
        "             `.:/++++/:.`  -////..:--`                                                                                                                                                          \n"
        "                 .-/+++++/-..::.`                                                                                                                                                               \n"
        "       `:::-..``    `.:/++++-                                                                                                                                                                   \n"
        "       -++++++///:--.```.-/-                                                                                                                                                                    \n"
        "        `.--:///++++++//::.                                                                                                                                                                     \n"
        "`--.          ``..-::///+/``---                                                 -+-                                                             ./oso- /++:                                     \n"
        "-oo+  -::::----....````... `ooo                  :s-                            /mo                                                            -dmmhy:`hmmo                                     \n"
        "-oo+  /+++++++++++++++++/. `ooo                  om:                            /mo             ````     ```      ```    ``.``      ```  `.``  ommd`` `hmmo       ``.``    ```     ```     ```  \n"
        "-oo+  ...----::::////+++/` `ooo      `/ssyss+:`.ohmyoo` .+ssyss+-     -+syys+-  /mo    -o+.  .ohdmmdho- -hdd/   `sdds` :shmmmdy/`  .hddshdmmhoydmmmhy:`hmmo    .+hdmmmds- .ddd/   .ddh-   +ddh. \n"
        "-oo+  ```````````````````  `ooo     .yh-.``-/-  .sm/.` `/o-```-sd+  .sd+-..-++` /mo  .odo.  :dmmy+/smmm: +mmh-  /mmd- +mmh+:/smmy- .dmmdo/+s:`/ymmm++.`hmmo   .dmmh++smmd+`ommd` `ymmmy  .hmm+  \n"
        "-oo+  +oooooooooooooooooo- `ooo     -dy.         om:           -dy` +m/         /mo`+dy-   `smmy`  `smmy``smms`.hmm/ -dmd+---:hmmo`.dmm+       ommd   `hmmo   ommh.   ommh..ymm+ +mmdmm/ ommy.  \n"
        "-oo+  /++++++++++++++++++. `ooo      -oyhyyys/`  om:   `:osyyyyymy``sm-         /myhyhd:   `smms    +mmh` `dmm/smms  :dmmddddddddo`.dmm/       ommd   `hmmo   smmy`   /mmd. :dmd+dmy-ymd+hmd:   \n"
        "-oo+                       `ooo          ``.+do  om:   /do.    -dy``om:         /md/``od+` `ommh.  `ymmy`  :dmmmmy.  .hmd/`````.`  .dmm/       ommd    hmmo   +mmh-   smmy` `smmmmm- :dmmmmo    \n"
        "-oo+:::::::::::::::::::::::/ooo     -+:.```.od+  +mo.` /do.```.omy` .sd/.``.//` /mo    +dy. -ymmdysdmmh-    +mmmh-    :dmmyoosdd+` .dmm/       ommd    ommmso.`ymmdyshmmh:   .hmmm+   +mmmd`    \n"
        "-oooooooooooooooooooooooooooooo     ./syyyyyo:`  `:sys.`:syyyys+yo`  `:syyyyo:` :h/     :ys` `:shddhs/`     `ohy/      ./shddhy+-  .shh:       /hhy    `:syhs. `:oyhdhs/.     /hho`   `shh/     \n"

More sensibly, use endl. This is subtly different from just "\n" after each line, because you'll also flush the output stream.

like image 64
John Feminella Avatar answered Sep 29 '22 04:09

John Feminella