如何在c代码或c ++代码中显示此类文本?

时间:2021-02-01 00:29:00

We have to do some project for our semester. So to make the project we are showing our title of project and we want to display our project like this :

我们必须为我们的学期做一些项目。因此,为了使项目我们显示项目的标题,我们想要显示我们的项目,如下所示:

 ____                                 _   ____        _            
|  _ \ ___ _ __ ___  ___  _ __   __ _| | |  _ \  __ _(_)_ __ _   _ 
| |_) / _ \ '__/ __|/ _ \| '_ \ / _` | | | | | |/ _` | | '__| | | |
|  __/  __/ |  \__ \ (_) | | | | (_| | | | |_| | (_| | | |  | |_| |
|_|   \___|_|  |___/\___/|_| |_|\__,_|_| |____/ \__,_|_|_|   \__, |
                                                             |___/ 

I tried to use printf but could not do. I could not accomplish it.

我试图使用printf但是无法做到。我无法完成它。

First I tried like this

首先,我试着这样做

printf(" ____                                 _   ____        _            ");
printf("|  _ \ ___ _ __ ___  ___  _ __   __ _| | |  _ \  __ _(_)_ __ _   _ ");
printf("| |_) / _ \ '__/ __|/ _ \| '_ \ / _` | | | | | |/ _` | | '__| | | |");
printf("|  __/  __/ |  \__ \ (_) | | | | (_| | | | |_| | (_| | | |  | |_| |");
printf("|_|   \___|_|  |___/\___/|_| |_|\__,_|_| |____/ \__,_|_|_|   \__, |");
printf("                                                             |___/ ");

And the problem was \ character was creating problem. If I replace \ with \\ it will not appear as I want to.

问题是\字符正在创造问题。如果我用\\替换\它将不会出现我想要的。

So how could I accomplish it? :(

那我该怎么做呢? :(

Is there any way?

有什么办法吗?

2 个解决方案

#1


4  

Use puts() to have newline characters inserted automatically

使用puts()自动插入换行符

puts(" ____                                 _   ____        _            ");
puts("|  _ \\ ___ _ __ ___  ___  _ __   __ _| | |  _ \\  __ _(_)_ __ _   _ ");
puts("| |_) / _ \\ '__/ __|/ _ \\| '_ \\ / _` | | | | | |/ _` | | '__| | | |");
puts("|  __/  __/ |  \\__ \\ (_) | | | | (_| | | | |_| | (_| | | |  | |_| |");
puts("|_|   \\___|_|  |___/\\___/|_| |_|\\__,_|_| |____/ \\__,_|_|_|   \\__, |");
puts("                                                             |___/ ");

or insert newline characters manually.

或手动插入换行符。

printf(" ____                                 _   ____        _            \n");
printf("|  _ \\ ___ _ __ ___  ___  _ __   __ _| | |  _ \\  __ _(_)_ __ _   _ \n");
printf("| |_) / _ \\ '__/ __|/ _ \\| '_ \\ / _` | | | | | |/ _` | | '__| | | |\n");
printf("|  __/  __/ |  \\__ \\ (_) | | | | (_| | | | |_| | (_| | | |  | |_| |\n");
printf("|_|   \\___|_|  |___/\\___/|_| |_|\\__,_|_| |____/ \\__,_|_|_|   \\__, |\n");
printf("                                                             |___/ \n");

#2


1  

Character '\' has a special meaning in C and C++ strings. It's used as a prefix to get special characters. For example new line is '\n'. Which by the way you have to add to the end of all your lines. If you want to output '\' you have to double to make it '\'.

字符'\'在C和C ++字符串中具有特殊含义。它被用作获取特殊字符的前缀。例如,新行是'\ n'。顺便说一句,你必须添加到所有行的末尾。如果你想输出'\',你必须加倍才能使它'''。

The line

printf("|_|   \___|_|  |___/\___/|_| |_|\__,_|_| |____/ \__,_|_|_|   \__, |");

Should actually be

应该是

printf("|_|   \\___|_|  |___/\\___/|_| |_|\\__,_|_| |____/ \\__,_|_|_|   \\__, |\n");

Do the for the rest of the lines. Also on some operating systems like Windows you have to put both newline and carriage return at the end of the string so it should be '\r\n' at the end not just '\n'

做剩下的行。同样在Windows等操作系统上,你必须在字符串的末尾放置换行符和回车符,所以它最后应该是'\ r \ n'而不仅仅是'\ n'

#1


4  

Use puts() to have newline characters inserted automatically

使用puts()自动插入换行符

puts(" ____                                 _   ____        _            ");
puts("|  _ \\ ___ _ __ ___  ___  _ __   __ _| | |  _ \\  __ _(_)_ __ _   _ ");
puts("| |_) / _ \\ '__/ __|/ _ \\| '_ \\ / _` | | | | | |/ _` | | '__| | | |");
puts("|  __/  __/ |  \\__ \\ (_) | | | | (_| | | | |_| | (_| | | |  | |_| |");
puts("|_|   \\___|_|  |___/\\___/|_| |_|\\__,_|_| |____/ \\__,_|_|_|   \\__, |");
puts("                                                             |___/ ");

or insert newline characters manually.

或手动插入换行符。

printf(" ____                                 _   ____        _            \n");
printf("|  _ \\ ___ _ __ ___  ___  _ __   __ _| | |  _ \\  __ _(_)_ __ _   _ \n");
printf("| |_) / _ \\ '__/ __|/ _ \\| '_ \\ / _` | | | | | |/ _` | | '__| | | |\n");
printf("|  __/  __/ |  \\__ \\ (_) | | | | (_| | | | |_| | (_| | | |  | |_| |\n");
printf("|_|   \\___|_|  |___/\\___/|_| |_|\\__,_|_| |____/ \\__,_|_|_|   \\__, |\n");
printf("                                                             |___/ \n");

#2


1  

Character '\' has a special meaning in C and C++ strings. It's used as a prefix to get special characters. For example new line is '\n'. Which by the way you have to add to the end of all your lines. If you want to output '\' you have to double to make it '\'.

字符'\'在C和C ++字符串中具有特殊含义。它被用作获取特殊字符的前缀。例如,新行是'\ n'。顺便说一句,你必须添加到所有行的末尾。如果你想输出'\',你必须加倍才能使它'''。

The line

printf("|_|   \___|_|  |___/\___/|_| |_|\__,_|_| |____/ \__,_|_|_|   \__, |");

Should actually be

应该是

printf("|_|   \\___|_|  |___/\\___/|_| |_|\\__,_|_| |____/ \\__,_|_|_|   \\__, |\n");

Do the for the rest of the lines. Also on some operating systems like Windows you have to put both newline and carriage return at the end of the string so it should be '\r\n' at the end not just '\n'

做剩下的行。同样在Windows等操作系统上,你必须在字符串的末尾放置换行符和回车符,所以它最后应该是'\ r \ n'而不仅仅是'\ n'