Can someone give a rundown on how to use unicode in arrays and such?

I need to know so I could include some unicode characters into a 2D array. So information would be greatly appreciated, headers, types, anything. If you need something to build around, Heres a 2D character array([4][4]) setup with unicode in it, so it won't work. Just take this and add on to it, I guess. Thanks!

1
2
3
4
5
6
7
8
#include <iostream>

using namespace std;

char Array[4][4]{{"▓▓▓▓"},
                 {"▓▓▓▓"},
                 {"▓▓▓▓"},
                 {"▓▓▓▓"}};
1 unicode is the size of 2 char, you might have to use wide char wchar_t I think... you'll have to use wide everything for it like std::wcout and stuff
-- oh, you might have to put an 'L' in front of the string literals also L"string"
I have included

#define UNICODE

and it will print normal text(When I use wcout opposed to cout) to the console when I ask it to now, I have an L prefix to whatever it is. Like:

1
2
3
4
wchar_t Array[4][4]{{L"aaa"},
                 {L"aaa"},
                 {L"aaa"},
                 {L"aaa}};  


Will work. However, when I add actual unicode characters, it just gives me blankness. As if it were all just whitespace characters. My code is:

1
2
3
4
5
6
7
8
9
10
11
12
wchar_t Map[12][12] = {{L"╔═════════╗"},
                    {L"║         ║"},
                    {L"║      $  ║"},
                    {L"║         ║"},
                    {L"║ $       ║"},
                    {L"║         ║"},
                    {L"║         ║"},
                    {L"║         ║"},
                    {L"║        $║"},
                    {L"║         ║"},
                    {L"║         ║"},
                    {L"╚════════╝"}};


The place where I use it:

1
2
3
4
5
6
7
8
9
10
11
12
	system("CLS");

	for(int col=0;col<12;col++)
	{

		for(int row=0;row<12;row++)
    {
			wcout << Map[col][row];
	}
		cout << endl;

    }


Like I said, it doesn't print out the characters I added.
you are going to have to set your console up to take the unicode... as I've never had to do that part... check this out:

http://www.codeproject.com/KB/cpp/unicode_console_output.aspx

-- edit: i'll go over it as well, so I can learn too
Last edited on
I didn't realize it would be this complicated. :l
There's some misinformation in this thread.

craniumonempty wrote:
1 unicode is the size of 2 char, you might have to use wide char wchar_t I think... you'll have to use wide everything for it like std::wcout and stuff


Unicode is not necessarily larger than a char. You're mixing up "wide" characters with unicode characters (and even wide chars aren't necessarily 2 bytes -- on some systems they're larger).

Using wide everything won't make unicode work on the console. In fact, wcout does practically nothing (it narrows data before outputting, effectively making it pretty useless).

On *nix systems, outputting Unicode to the console is as simple as outputting UTF-8. On Windows, however, it is a considerable process. I walked someone through it before in a 4-page thread a long time ago. I have the link book marked at home -- when I get home I'll post it here if I remember.


Also, I have to give the obligatory link...

http://www.cplusplus.com/forum/articles/28558/
I don't know, when I use cout, I get numbers as opposed to wcout with wchar_t... yeah, sorry for the other misinfo
oh, plus that page only helps with a little, I'm just now finding out how difficult cmd is with anything but what it expects... I guess if you really wanted to do it, you could use a different console, or make your own...
Disch, that thread answered against every reason I chose to make a game in the console instead. XD Great reasons why not to. Thanks for the awesome help. And you to cranium.
Topic archived. No new replies allowed.