Jump to content
  • Advertisement
Sign in to follow this  

displaying unicode strings?

This topic is 4035 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Im making this poker program in C++, and Im trying to make it display the suits using the unicode symbols (2660-2668). Im running this in putty, and Im having some trouble. Im not sure whether its the code or putty's character set. Ive tried various different ways of doing this but I think this one is the one that should work: #include <iostream> #include <string> #include <locale> using namespace std; int main() { for(unsigned int i = 2660; i < 2670; i++) { basic_string<wchar_t> str(L"0"); str[0] = (wchar_t)i; wcout << i << L"\t" << str << endl; } } however all i get is question marks as output. I changed puttys character set to be UTF-8, so unless Im missing something my codes probably wrong. Any help would be great. Also, is there some way to check if its possible to output these symbols or not? I would rather have "5 spades" than "5 ?".

Share this post


Link to post
Share on other sites
Advertisement
Sounds like either the console code is playing games with the character stream trying to fit it into the current locale or the font it is using simply doesn't support the characters you are trying to print.

I don't know how *nix works in this regard. I know on Windows the console is fairly limited in these things because it has to be compatible with all the 500 billion different character sets that existed pre-Unicode.

Share this post


Link to post
Share on other sites
Quote:
Original post by michael879
well Id be happy if I could just find a way to print out using the DOS character set. Anyone know how to do that?


You might want to take a look at how the console displays the first few ("nonprintable") ASCII characters by default ;)

Share this post


Link to post
Share on other sites
Quote:
Original post by michael879
Im making this poker program in C++, and Im trying to make it display the suits using the unicode symbols (2660-2668). Im running this in putty, and Im having some trouble. Im not sure whether its the code or putty's character set. Ive tried various different ways of doing this but I think this one is the one that should work.... I changed puttys character set to be UTF-8, so unless Im missing something my codes probably wrong. Any help would be great. Also, is there some way to check if its possible to output these symbols or not? I would rather have "5 spades" than "5 ?".


Those characters would be from which Unicode set, UTF-16 (or Microsoft's proprietary variant)? I would think that if you're putting out wide characters to a wide stream you would want to examine them using a wide character viewer. UTF-8 is a multibyte character set. I would expect to see garbage given your description.

Here's some suggestion to try (I haven't tried any of the, I don't have access to a Windows machine).

(1) Try using wchar_t as the type of i -- maybe there's a byte ordering problem (always possible with wide characters).

(2) Try using a narrow stream instead. The stream should convert your wide characters to multibyte characters automatically, assuming you've set the locale correctly.

(3) Make sure the output stream is imbued with a locale that supports UTF-8 output.

(4) If you're using MinGW on Windows (just a guess) be aware that wide character support doesn't work. Try using another compiler+library (MSVC?).

(5) Redirec the output into a file and hexdump the file -- maybe you can get a clue (byte ordering problems, etc).

Hopefully one of these suggestoins might reveal a useful angle for attacking your problem.

--smw

Share this post


Link to post
Share on other sites
As already mentioned, you need to make sure your client is using the correct font, as essentially you're telling the client to draw a nice big green tree, but the client doesn't have that graphic.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!