char card symbols problem

I'm trying to output the unicode characters for a card deck. I need help in implementing it. I didn't think it would be complicated.

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

#include<iostream>

int main ()
{
	std::cout<<"\u2660"<<std::endl;
	char a = '\u2666';
	std::cout<<a;
	/*
	2660  BLACK SPADE SUIT
2661  WHITE HEART SUIT
2662  WHITE DIAMOND SUIT
2663  BLACK CLUB SUIT
2664  WHITE SPADE SUIT
2665  BLACK HEART SUIT
2666  BLACK DIAMOND SUIT
2667  WHITE CLUB SUIT
*/
	return 0;
}



â™ 
¦
Last edited on
u can't put it in char as it is 1byte only and this character takes more than one byte
Ok, so how do I print any one of the above characters. Am using Eclipse IDE.
Hi,

Have a look at std::wcout

http://en.cppreference.com/w/cpp/io/cout
Ok, so I changed in the eclipse IDE run->run configurations->common-->other to UTF-8.

https://decoding.wordpress.com/2010/03/18/eclipse-how-to-change-the-console-output-encoding/

Now I am printing card suit characters. My only concern left is portability with the unicode.

Also I get 2 different symbols with same code and slight different printing method. Why is that?

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <clocale>

using namespace std;

int main ()
{
	std::cout<<"\u2664"<<std::endl;
	char a = '\u2664';
	std::cout<<a;

	return 0;
}




♤
�
Last edited on
Again, a character is only one byte and cannot hold the value of '\u2664'. You'll need to put it into a string like you did on line 8.
Your compiler should have warned you that you were trying to store something in a char that didn't fit. if it did warn you, start reading the compiler warnings; they're there for a reason. If it didn't warn you, turn on the warnings.
Thx, got it.

Using the same approach to successfully outputting spade, heart, diamond and club symbols, I tried printing a card unicode icon:https://en.wikipedia.org/wiki/Playing_cards_in_Unicode
Fail.

What do I need to do instead?

1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
#include <clocale>

int main ()
{

	std::cout<<"\u1F0A1"; //ACE of spades card 
	std::cout<<"\u1F0A3"; //two of spades card 

	return 0;
}



Ἂ1Ἂ3
Last edited on
What does this code give you:

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

int main ()
{
	std::cout<<"🂡" << std::endl; //ACE of spades card 
	std::cout<<"\U0001F0A1" << std::endl; // \U for 32 bit unicode
	return 0;
}
Last edited on
Topic archived. No new replies allowed.