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

Mark picture Mark · Feb 2, 2010 · Viewed 28.1k times · Source

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?

Answer

John Feminella picture John Feminella · Feb 2, 2010

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.