-
Wierd chars...
Hi all! I was making some little application that needed to convert some chars into others, just so a txt file seems unreadable... But I got some reeeallly wierd problem, I can go around it and make things work fine, but I get this strange problem:
I have in my program an "unsigned char" buffer that I use to read on a file an check to see if the char is equal to something and then I do something with it. Somewhere I have that piece of code:
Code:
iFile >> buffer; //Where iFile is an "ifstream" and "buffer" the char...
if (buffer == '¤')
//do something...
else
//...
So there I believe I'm having a compiler error. I expect my program to "do something" when the read buffer is equal to the unsigned char '¤' value, or 164... But it never works. If I use the debugger and check what is "(buffer == '¤')" while buffer is supposed to be 164 (¤), it tells me its true (one would hope), but then the code-cursor don't get to the "do something" line and instead it goes inside the "else"... I think that's totally wierd, I use MSVC++ 2003, and I don't see why something that is true could be seen as false...
But I found out that if I wrote:
Code:
if (buffer == 164)
//instead of
if (buffer == '¤')
it would work... Though these are supposed to be equal (¤ == 164)...
Any idea why this would do something like that?
-
Looks like you editor and the compiler use different character encodings.
Kurt
-
Well, I believe that I can only type in ASCII codes, because I can't save files that contain other characters from sets like unicode... And the problem is only runtime....
-
And the most important part is again left out -- what is the declaration of buffer? Is it really just an unsigned char? Or an array?
-
Yeah, it's not an array...
-
So is there something that I can do to change the compiler's character set?
-
Doesn't look like it:
http://msdn2.microsoft.com/en-us/library/19z1t1wy.aspx
Try using the \xnn escape syntax to get a specific character. Of course, runtime character set issues still play in, but at least it'll do something.
-
Not the compiler, no. But you can and should change your editor encoding to match your compiler's.
I had a similar problem before. The solution is to move to unicode, if you want to use the Windows representation of the extended ASCII codes.
-
Hmm... I tried to change the coding to unicode, but I'm stuck because I realized that there are many types of unicodes I can choose from, but I don't know which one I should use.
I have something like UTF-8, 65000, 1200, big-endian,... Am I lost?
Let's say I try to write to the console "←↑→↓" it gets out this way "âââòêâââ& #226;êêô", (approximatively that way...)
but the problem is that I had only 4 characters, and it prints out 12 characters...