2

I'm attempting to put in ASCII art in a C++ program and did so by manually printing each line, but the outcome was nothing like the ASCII art. It's like:

Enter image description here

Does this occur because the characters are not recognizable by the prompt or have I not done it correctly?

Here is the ASCII art I'm trying to do:

_____/\\\\\\\\\________/\\\\\\\\\\\__________/\\\\\\\\\__/\\\\\\\\\\\__/\\\\\\\\\\\_        
 ___/\\\\\\\\\\\\\____/\\\/////////\\\_____/\\\////////__\/////\\\///__\/////\\\///__       
  __/\\\/////////\\\__\//\\\______\///____/\\\/_______________\/\\\_________\/\\\_____      
   _\/\\\_______\/\\\___\////\\\__________/\\\_________________\/\\\_________\/\\\_____     
    _\/\\\\\\\\\\\\\\\______\////\\\______\/\\\_________________\/\\\_________\/\\\_____    
     _\/\\\/////////\\\_________\////\\\___\//\\\________________\/\\\_________\/\\\_____   
      _\/\\\_______\/\\\__/\\\______\//\\\___\///\\\______________\/\\\_________\/\\\_____  
       _\/\\\_______\/\\\_\///\\\\\\\\\\\/______\////\\\\\\\\\__/\\\\\\\\\\\__/\\\\\\\\\\\_ 
        _\///________\///____\///////////___________\/////////__\///////////__\///////////__

Code:

cout << "_____/\\\\\\\\\________/\\\\\\\\\\\__________/\\\\\\\\\__/\\\\\\\\\\\__/\\\\\\\\\\\_        \n";
cout << " ___/\\\\\\\\\\\\\____/\\\/////////\\\_____/\\\////////__\/////\\\///__\/////\\\///__       \n";
cout << "  __/\\\/////////\\\__\//\\\______\///____/\\\/_______________\/\\\_________\/\\\_____      \n";
cout << "  _\/\\\_______\/\\\___\////\\\__________/\\\_________________\/\\\_________\/\\\_____     \n";
cout << "    _\/\\\\\\\\\\\\\\\______\////\\\______\/\\\_________________\/\\\_________\/\\\_____    \n";
cout << "    _\/\\\/////////\\\_________\////\\\___\//\\\________________\/\\\_________\/\\\_____   \n";
cout << "      _\/\\\_______\/\\\__/\\\______\//\\\___\///\\\______________\/\\\_________\/\\\_____  \n";
cout << "       _\///________\///____\///////////___________\/////////__\///////////__\///////////__\n";
4
  • Show the code that is responsible for printing Commented Jun 11, 2016 at 16:21
  • It's literally "cout << "ASCII LINE \n"; for all the lines
    – James
    Commented Jun 11, 2016 at 16:23
  • you're missing the leading spaces and your lines break, seems easy to fix if you could actually see the code
    – Leeor
    Commented Jun 11, 2016 at 16:25
  • I think using cout << "blablabla" << endl; instead of cout << "blablabla\n"; should work too... hard to say what endl type your iostream is using (I am not using it for decades) but my bet is "\r\n" ...
    – Spektre
    Commented Mar 16, 2017 at 9:56

1 Answer 1

28

The escape sequences are interpreted as single special or other characters, hence the strange output. "\\" means '\' for example.

You can use a raw string literal:

#include <iostream>

int main()
{
    std::cout << R"(
_____/\\\\\\\\\________/\\\\\\\\\\\__________/\\\\\\\\\__/\\\\\\\\\\\__/\\\\\\\\\\\_        
 ___/\\\\\\\\\\\\\____/\\\/////////\\\_____/\\\////////__\/////\\\///__\/////\\\///__       
  __/\\\/////////\\\__\//\\\______\///____/\\\/_______________\/\\\_________\/\\\_____      
   _\/\\\_______\/\\\___\////\\\__________/\\\_________________\/\\\_________\/\\\_____     
    _\/\\\\\\\\\\\\\\\______\////\\\______\/\\\_________________\/\\\_________\/\\\_____    
     _\/\\\/////////\\\_________\////\\\___\//\\\________________\/\\\_________\/\\\_____   
      _\/\\\_______\/\\\__/\\\______\//\\\___\///\\\______________\/\\\_________\/\\\_____  
       _\/\\\_______\/\\\_\///\\\\\\\\\\\/______\////\\\\\\\\\__/\\\\\\\\\\\__/\\\\\\\\\\\_ 
        _\///________\///____\///////////___________\/////////__\///////////__\///////////__        
)" << '\n';

    return 0;
}

live demo

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.