In C++, how can I cout a logo that features many special characters?

626 views Asked by At

I have a logo that features many special characters, such as escape characters, and I want to print it to the terminal. How should I do this without the compiler throwing "unknown escape sequence" errors?

Here is some example code (that features only one problematic character -- not, say, hundreds):

void print_logo();

int main(){
    print_logo();
    return 0;
}

void print_logo(){
    std::cout << "\_ hello _/\n";
}

Note that manually escaping all of the special characters in the logo is not an option.

2

There are 2 answers

5
ixSci On BEST ANSWER

How about raw literals?

#include <iostream>

int main()
{
    const char* tree = R"===(
      *             ,
                       _/^\_
                      <     >
     *                 /.-.\         *
              *        `/&\`                   *
                      ,@.*;@,
                     /_o.I %_\    *
        *           (`'--:o(_@;
                   /`;--.,__ `')             *
                  ;@`o % O,*`'`&\
            *    (`'--)_@ ;o %'()\      *
                 /`;--._`''--._O'@;
                /&*,()~o`;-.,_ `""`)
     *          /`,@ ;+& () o*`;-';\
               (`""--.,_0 +% @' &()\
               /-.,_    ``''--....-'`)  *
          *    /@%;o`:;'--,.__   __.'\
              ;*,&(); @ % &^;~`"`o;@();         *
              /(); o^~; & ().o@*&`;&%O\
        jgs   `"="==""==,,,.,="=="==="`
           __.----.(\-''#####---...___...-----._
         '`         \)_`"""""`
                 .--' ')
               o(  )_-\
                 `"""` `
    )===";
    std::cout << tree;
};
1
Software_Designer On

Add a backslash \ to every slash :

void print_logo(){
    std::cout << "\\_ hello _\/\n";
}

Output:

\_ hello _/




Press any key to continue