Reading out wchar_t values
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.
What compiler are you using? What settings have you enabled? Have you changed the project configuration at all?
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.
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.
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.
P.S. Then again I just tried NOT doing that and it didn't make any difference.
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.
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.
Quote:Original post by shukapi
Are you sure that you've actually got a wide-character 'f' to read in?
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.
I am assuming cin and wcin read the same serial sequence of bytes.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement