Results 1 to 14 of 14
  1. #1
    ヽಠ_ಠᕤ Headrockin' ᕦಠ_ಠ╯
    MPGH Member
    IV2B's Avatar
    Join Date
    Jan 2011
    Gender
    male
    Posts
    1,163
    Reputation
    101
    Thanks
    229
    My Mood
    Inspired

    Quick help about printing ascii art into console.

    Hello,i'm just starting out programming (atm,i've barely started while,lolol) and i'd like to know a little information.
    I'd need to copy/paste ascii text lines like this one:
    Code:
    ▒█████▄█▀▀██▀▓░  ▄▄▄▄▄▄░ ▓██████████████▓▓▓▒▒▄▀███░░▄▄░▀▀█▄ ▄ ▀▀ ▄▄██████████▓░

    At a decenty rate as i could assign 3 values to each character used,then slowly translating them,or setting char variables named ▒/░/▓ to their respective ascii code (177/176/178) and add a << after every character,but both options would be too slow for almost anything.

    The issue here is that pasting such line using cout like this:
    Code:
    cout<<"shitgoesherelol";
    would only give me "?" characters.
    I've already looked up many tutorials on the web and various other forums but none of them helped,a little help would be appreciated

    P.s. please keep it simple enough,i'm a beginner :<

  2. #2
    `Bobs Bees's Avatar
    Join Date
    Oct 2009
    Gender
    male
    Posts
    930
    Reputation
    33
    Thanks
    183
    My Mood
    Relaxed
    Most likely you're using illegal characters or you don't have the keyboard language installed to handle them. Maybe you're also not making new lines as well but with the ??? is illegal characters or unknown keyboard language.
    User CP -> Edit Signature -> Make less then one line.

  3. #3
    Threadstarter
    ヽಠ_ಠᕤ Headrockin' ᕦಠ_ಠ╯
    MPGH Member
    IV2B's Avatar
    Join Date
    Jan 2011
    Gender
    male
    Posts
    1,163
    Reputation
    101
    Thanks
    229
    My Mood
    Inspired
    Quote Originally Posted by `Bobs Bees View Post
    Most likely you're using illegal characters or you don't have the keyboard language installed to handle them. Maybe you're also not making new lines as well but with the ??? is illegal characters or unknown keyboard language.
    Yep,that's the warning i get,characters i use seem to be illegal... Lolwut is dis?

  4. #4
    abuckau907's Avatar
    Join Date
    Dec 2012
    Gender
    male
    Location
    other side of the wire
    Posts
    1,342
    Reputation
    162
    Thanks
    239
    My Mood
    Cold
    Ascii stores text as 1 bytes. 8 bits. Well, actualy 7 bits.

    0000000 to 1111111

    0 to 127

    128-255 (using 8th bit) probably works too.
    'Some things that can be counted, don't matter. And some things that matter, can't be counted' - A.E.
    --
     

    My posts have some inaccuracies/are wrong/wrong keyword(s) used.
    They're (maybe) pretty close, and I hope they helped you, not created confusion. Take with grain of salt.

    -if you give rep, please leave a comment, else it means less.

  5. #5
    Threadstarter
    ヽಠ_ಠᕤ Headrockin' ᕦಠ_ಠ╯
    MPGH Member
    IV2B's Avatar
    Join Date
    Jan 2011
    Gender
    male
    Posts
    1,163
    Reputation
    101
    Thanks
    229
    My Mood
    Inspired
    Quote Originally Posted by abuckau907 View Post
    Ascii stores text as 1 bytes. 8 bits. Well, actualy 7 bits.

    0000000 to 1111111

    0 to 127

    128-255 (using 8th bit) probably works too.
    Writing:
    Code:
    char ▒=177;
    cout<<▒;
    Would work indeed,and i do know how char data is stored.
    However,i am looking for an efficient way to do this,as doing
    Code:
    cout<<▒;
    will paste an ? symbol in the console and writing:
    Code:
    cout<<▒<<▓<<▒<<▒<<░...;
    Takes really long.

  6. #6
    abuckau907's Avatar
    Join Date
    Dec 2012
    Gender
    male
    Location
    other side of the wire
    Posts
    1,342
    Reputation
    162
    Thanks
    239
    My Mood
    Cold
    Quote Originally Posted by IV2B View Post
    ..
    instead of calling cout 100,000 times, store all the data into a big buffer and call cout once.
    Last edited by abuckau907; 10-15-2013 at 02:43 PM.
    'Some things that can be counted, don't matter. And some things that matter, can't be counted' - A.E.
    --
     

    My posts have some inaccuracies/are wrong/wrong keyword(s) used.
    They're (maybe) pretty close, and I hope they helped you, not created confusion. Take with grain of salt.

    -if you give rep, please leave a comment, else it means less.

  7. #7
    abuckau907's Avatar
    Join Date
    Dec 2012
    Gender
    male
    Location
    other side of the wire
    Posts
    1,342
    Reputation
    162
    Thanks
    239
    My Mood
    Cold
    ooh

    Code:
    char ▒=177; // <-----
    cout<<▒;
    The variable name is the unicode symbol?


    That isn't allowed. Only ascii letters, numbers and _


    Did that change? -What compiler are you using? You should try to keep your source in ascii for portability (?).
    edit:
    Code:
    float �� = 0.0f; 
    float �� = 1.1f;
    �� += 1; // lol?
    Anyway,
    instead of calling cout 100,000 times, store all the data into a big buffer and call cout once.
    Last edited by abuckau907; 10-15-2013 at 03:12 PM.
    'Some things that can be counted, don't matter. And some things that matter, can't be counted' - A.E.
    --
     

    My posts have some inaccuracies/are wrong/wrong keyword(s) used.
    They're (maybe) pretty close, and I hope they helped you, not created confusion. Take with grain of salt.

    -if you give rep, please leave a comment, else it means less.

  8. #8
    Threadstarter
    ヽಠ_ಠᕤ Headrockin' ᕦಠ_ಠ╯
    MPGH Member
    IV2B's Avatar
    Join Date
    Jan 2011
    Gender
    male
    Posts
    1,163
    Reputation
    101
    Thanks
    229
    My Mood
    Inspired
    How excatly would i do it?
    Also i use dev c++/visual studio.
    And yeah, ▒ is the name of the variable and it's shown in the editor :O

  9. #9
    abuckau907's Avatar
    Join Date
    Dec 2012
    Gender
    male
    Location
    other side of the wire
    Posts
    1,342
    Reputation
    162
    Thanks
    239
    My Mood
    Cold
    It will work, but not good for portability. You don't want unicode variable names. Maybe I'm bias because I speak English?

    Read about arrays. You need to make one big enough, and put the data in it.
    'Some things that can be counted, don't matter. And some things that matter, can't be counted' - A.E.
    --
     

    My posts have some inaccuracies/are wrong/wrong keyword(s) used.
    They're (maybe) pretty close, and I hope they helped you, not created confusion. Take with grain of salt.

    -if you give rep, please leave a comment, else it means less.

  10. #10
    abuckau907's Avatar
    Join Date
    Dec 2012
    Gender
    male
    Location
    other side of the wire
    Posts
    1,342
    Reputation
    162
    Thanks
    239
    My Mood
    Cold
    maybe save each "piece of art" to it's own text file.

    Read the entire file, and display. Or you're going to be defining a lot of the art "inside your code". Depends what you're going for.
    'Some things that can be counted, don't matter. And some things that matter, can't be counted' - A.E.
    --
     

    My posts have some inaccuracies/are wrong/wrong keyword(s) used.
    They're (maybe) pretty close, and I hope they helped you, not created confusion. Take with grain of salt.

    -if you give rep, please leave a comment, else it means less.

  11. #11
    Shanks_'s Avatar
    Join Date
    Jan 2013
    Gender
    male
    Posts
    60
    Reputation
    45
    Thanks
    8
    My Mood
    Pensive
    Outputting unicode varies wildly by platform in C++. There is no one "solution", besides perhaps a library that solves all the different solutions for you. If you're just targeting today's Linux and OSX, you've really got no problem, since the console is almost certainly using UTF-8 as its char encoding, and your source file will be as well. If both are true, then you can just paste the unicode straight into the source of the program, and it'll work with no problems.

    If your system saves its text files in some other encoding, pasting it in isn't going to work, but you can express your unicode as universal character names. In C++ in a UTF-8 document, "▒" is the same as "\u2592". Think of it as a way of escaping unicode symbols so they work anywhere. Just use any online unicode lookup to find the hex value you put after the \u. And yes, that is hex; the ▒ character we seem to be using as an example is, due to strange luck, only base 10 digits, even in hex.

    So now your program will work when run on any sensible UTF-8 console. However, Windows, unlike almost every other operating system, is off in its own world doing its own thing. It, by default, uses the code page 437, (code page being a way of expressing the current character encoding), which is essentially one extended ASCII character encoding out of many, and the one MS and IBM have used since back when Lincoln was president and dinos walked the Earth. This code page does include those symbols you want, (as you have observed, they're 176, 177, etc.) and you can output those, and it should work just fine.

    However, this is ugly. It involves outputting completely different information that just gets represented the same by the character encoding. Theoretically you can do better, by telling cmd to be smart and use UTF-8. Once it's using UTF-8, you can output your unicode symbols just like in Linux and OSX. As far as I can tell, after you include windows.h (and any other proprietary instruments of developer lock-in Microsoft has given you that you need for other things), calling SetConsoleOutputCP(65001) before you output anything sets the current code page to 65001, which is the magic number for UTF-8. Then it may work. I'm not going to test it, so that will be the next thing for you to try.

    Also, yes, setting variables to unicode names does not help you. Using one variable for each symbol is very bad as well. I would suggest making a vector of 1-unicode-character-long strings, each with whichever symbol you want. Makes everything really concise, since to get to "▒", all you'd need to do is go to symbolsArray[1] (or whichever index you want) instead of some random variable. This is also beneficial in the event that you're outputting a greyscale image in ASCII, as you can simply store progressively lightening symbols in each index.
    Last edited by Shanks_; 10-15-2013 at 08:39 PM.
    ♪♪ ♪ ♪doign it rite , evrybuddy will be dancin and were feeling it rite , evrybuddy will be dancin and be doign' it rite , evrybuddy will be dancign' wen were feeling all rite , evrybuddy will be dancig tonit♪e♪ ♪♪ ♪♪♪

  12. #12
    hkKenshin's Avatar
    Join Date
    Oct 2013
    Gender
    male
    Posts
    301
    Reputation
    28
    Thanks
    340
    You could store them in byte arrays then print them off using something like printf or cout.

  13. #13
    xVIRUZx's Avatar
    Join Date
    Feb 2013
    Gender
    male
    Posts
    248
    Reputation
    10
    Thanks
    52
    My Mood
    Drunk
    Quote Originally Posted by hkKenshin View Post
    You could store them in byte arrays then print them off using something like printf or cout.
    With a for loop too?

    Code:
    for (int i=0;i<MAX_CHARACTERS_HERE;i++) {
    cout << byte_array_here[i];
    // or printf(byte_array_here[i]);
    }
    blah blah blah

  14. #14
    abuckau907's Avatar
    Join Date
    Dec 2012
    Gender
    male
    Location
    other side of the wire
    Posts
    1,342
    Reputation
    162
    Thanks
    239
    My Mood
    Cold
    Quote Originally Posted by xVIRUZx View Post
    With a for loop too?
    Code:
    for (int i=0;i<MAX_CHARACTERS_HERE;i++) {
    cout << byte_array_here[i];
    // or printf(byte_array_here[i]);
    }

    That works, but it is bad to call cout for each individual character. For a 50x50 image that would be 2,500 calls to cout. I think calling any function that many times will take > 1 second. It would be better, for example, to call it 50 times, each time printing out 50 characters. That's 50 function calls vs. 2,500.

    @OP you need to store you 'art' in arrays. Either typing them manually into the IDE, or loading them from a text file.
    Once you have all the data in a single array, it's 1 function call to print it all out. Will go very fast.
    Last edited by abuckau907; 10-17-2013 at 09:16 AM.
    'Some things that can be counted, don't matter. And some things that matter, can't be counted' - A.E.
    --
     

    My posts have some inaccuracies/are wrong/wrong keyword(s) used.
    They're (maybe) pretty close, and I hope they helped you, not created confusion. Take with grain of salt.

    -if you give rep, please leave a comment, else it means less.

Similar Threads

  1. [Help Request] need some really quick help
    By yair in forum Java
    Replies: 3
    Last Post: 02-21-2012, 03:37 PM
  2. [Help Request] Quick Help Needed
    By TeamDarkness in forum Call of Duty Modern Warfare 3 Help
    Replies: 1
    Last Post: 02-06-2012, 07:58 PM
  3. [Help Request] Help About Project Blackout Account!
    By amlpz4 in forum Piercing Blow Help
    Replies: 7
    Last Post: 01-21-2012, 03:02 AM
  4. [Help Request] need help about Autoit command
    By xueyehan in forum Vindictus Help
    Replies: 3
    Last Post: 08-18-2011, 07:12 AM
  5. [Help Request] Need help, About CrossInjector.
    By CheatCreatorzz in forum CrossFire Help
    Replies: 5
    Last Post: 06-22-2011, 02:28 PM