When I try to do printf("----/");, the \ is removed from the output
#include <iostream>
int main() {
std::cout << ("Welcome to the game\n\n");
printf("--------\n");
printf("----O---\n");
printf("---/|\--\n");
printf("---/-\--\n");
}
output:
--------
----0---
---/|--
---/---
>Solution :
The answer has been given already: \ is special, because it’s the escape character, and you need to escape it with itself if you want a literal \ in the outoupt.
This, however, can make the drawing confused.
To improve the things, you can use raw strings literals
printf(R"(--------\n)");
printf(R"(----O---\n)");
printf(R"(---/|\--\n)");
printf(R"(---/-\--\n)");
Clearly, you can still have issues, if a string contains exactly the characters )", because it will be detected as the closing token of the string:
// +---- code invalid from here
// |
// v
printf(R"(-----)"---\n)");
but you can still solve it, for instance by adding another set of wrapping "s:
printf(R""(-----)"---\n)"");
or anything else in between the " and (, and between ) and " (not symmetrized):
printf(R"xyz(-----)"---\n)xyz");
// ^
// |
// +--- not zyx