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.
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:
would only give me "?" characters.Code:cout<<"shitgoesherelol";
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 :<
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.
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.
--
Writing:
Would work indeed,and i do know how char data is stored.Code:char ▒=177; cout<<▒;
However,i am looking for an efficient way to do this,as doing
will paste an ? symbol in the console and writing:Code:cout<<▒;
Takes really long.Code:cout<<▒<<▓<<▒<<▒<<░...;
ooh
The variable name is the unicode symbol?Code:char ▒=177; // <----- cout<<▒;
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:
Anyway,Code:float = 0.0f; float = 1.1f; += 1; // lol?
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.
--
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
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.
--
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.
--
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♪ ♪♪ ♪♪♪
You could store them in byte arrays then print them off using something like printf or cout.
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.
--