Jump to content
  • Advertisement
Sign in to follow this  
Spriggan82

Reading out wchar_t values

This topic is 3983 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

Hi, I'm having a problem reading out wide character variables. Here is the code. wchar_t buffer = 0; void ReadIn() { wcin >> buffer; wcout << buffer << endl; } when I enter 'f', I get a 0 as output. Thanks in advance for any help.

Share this post


Link to post
Share on other sites
Advertisement
What compiler are you using? What settings have you enabled? Have you changed the project configuration at all?

Share this post


Link to post
Share on other sites
Well, I could imagine that somewhere there is a typedef that just does

typedef unsigned short int wchar_t;

That would explain why you get a zero. That would basically invoke the >> operator for unsigned short int, which would probably fail because it expected a number but got the ASCII character 'f' instead, and just give a zero.

Share this post


Link to post
Share on other sites
Open your project settings, go to C++ -> Language and make sure "Treat wchar_t as Built-in Type" is set to yes.

P.S. Then again I just tried NOT doing that and it didn't make any difference.

Share this post


Link to post
Share on other sites
Are you sure that you've actually got a 'f' to read in?

Have you tried replacing ReadIn() with a non-wchar_t version? Print out the first two characters from std::cin and see if one of them is 'f'?

PS: I've never used wcin so I'm just going on what it looks like.

Share this post


Link to post
Share on other sites
Quote:
Original post by shukapi
Are you sure that you've actually got a wide-character 'f' to read in?

Share this post


Link to post
Share on other sites
A 2-byte wchar_t version of 'f' is typically made up of a 'f' byte and a '\0' byte IIRC. So when printing the first 2 char's, one of them should be a 'f'.

I am assuming cin and wcin read the same serial sequence of bytes.

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!