problems with showing letters/symbols in cout (newbie)

This is a discussion on problems with showing letters/symbols in cout (newbie) within the C++ Programming forums, part of the General Programming Boards category; Hello. i got a problem with showing a "picture to ascii" if you could call it that my code is ...

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    33

    Exclamation problems with showing letters/symbols in cout (newbie)

    Hello.
    i got a problem with showing a "picture to ascii" if you could call it that my code is here:

    Code:
    // Windows
    #include <iostream>
    #include <windows.h>
    using namespace std;
    
    
    int main()
    {
           cout << endl << "   *-------------------------------------------*";
           cout << endl << "   |__          __   _____                     |";
           cout << endl << "   |\ \        / /  |      \                   |";
           cout << endl << "   | \ \      / /   |   O   |                  |";
           cout << endl << "   |  \ \    / /    |    __/                   |";
           cout << endl << "   |   \ \  / /     | |\ \                     |";
           cout << endl << "   |    \ \/ /      | | \ \                    |";
           cout << endl << "   |     \__/       |_|  \_\                   |";
           cout << endl << "   *------------------------------------------*";
    
    getchar();
    }
    now it's ........ed up again xD. Every time i run it, it shows wierd text and not "vr" like it's suopused to.

    I know why this accours, at least i think. But is there any way i can prevent it? i have tried setting each line up in a string but it "........ed up" and my program chrased. I think some of the symbols in the line is bad for the cout.

    BUT how do i make this thing, so it actually works ?

  2. #2
    Registered User
    Join Date
    Nov 2007
    Posts
    46
    You need to escape the "\" with another "\", so when you wish to output a single "\", you have to output "\\".

  3. #3
    Registered User
    Join Date
    Feb 2009
    Posts
    33
    Thank you man it worked! But what do you do with one \ exactly? is \ somekind of endl; ?

  4. #4
    Registered User
    Join Date
    Nov 2007
    Posts
    46
    "\" is an escape character, that is, a character which results in an alternative interpretation of the following character(s). For more information, simply look up "Escape character" on Google.

  5. #5
    Registered User
    Join Date
    Feb 2009
    Posts
    33
    Thanks (:

  6. #6
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682
    And also use cin.get() method, instead of getchar(). Or include <cstdio> to use getchar.

    ssharish
    Life is like riding a bicycle. To keep your balance you must keep moving - Einstein

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie question: problems with fopen
    By Ikim in forum C Programming
    Replies: 11
    Last Post: 02-04-2006, 07:57 PM
  2. Newbie problems after first linux install ever...
    By Leeman_s in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 01-24-2003, 02:04 PM
  3. newbie problems with write()
    By lastninja in forum C Programming
    Replies: 5
    Last Post: 01-20-2002, 12:18 PM
  4. Problems with Newbie Text-RPG
    By Darkflame in forum C++ Programming
    Replies: 7
    Last Post: 09-12-2001, 09:52 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21