Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > unicode or just ignorance? Help please

Reply
Thread Tools

unicode or just ignorance? Help please

 
 
jalkadir
Guest
Posts: n/a
 
      10-18-2005
Can someone please explain to me why, if I type 'Ni(ALT-164)A' at the
windows prompt, I get '[c:\]Niña', but if my program does this:
int main(){
std::string str("Niña");
std::cout << str << std::endl;
return 0;
}

I get [C:\]Ni±a

Can someone please, please, give me a hand understanding this
problem?!!

TIA

 
Reply With Quote
 
 
 
 
mlimber
Guest
Posts: n/a
 
      10-18-2005
jalkadir wrote:
> Can someone please explain to me why, if I type 'Ni(ALT-164)A' at the
> windows prompt, I get '[c:\]Niña', but if my program does this:
> int main(){
> std::string str("Niña");
> std::cout << str << std::endl;
> return 0;
> }
>
> I get [C:\]Ni±a
>
> Can someone please, please, give me a hand understanding this
> problem?!!
>
> TIA


Perhaps different fonts are being used in the two windows?

Cheers! --M

 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      10-18-2005
jalkadir wrote:
> Can someone please explain to me why, if I type 'Ni(ALT-164)A' at the
> windows prompt, I get '[c:\]Niña', but if my program does this:
> int main(){
> std::string str("Niña");
> std::cout << str << std::endl;
> return 0;
> }
>
> I get [C:\]Ni±a
>
> Can someone please, please, give me a hand understanding this
> problem?!!


I don't know what the problem is. Some conversion is applied somewhere,
but it doesn't say where and how. I think the contents of string literals
are only specified in "Basic character set", and ALT-164 is "Extended
ASCII" (if your basic set is ASCII). The behaviour is essentially
undefined unless you use the proper escape notation:

#include <vector>
#include <string>
#include <iostream>

int main(){
std::string str("Ni\xa4" "a"); // Niña
std::cout << str << std::endl;
return 0;
}

V
 
Reply With Quote
 
red floyd
Guest
Posts: n/a
 
      10-18-2005
Victor Bazarov wrote:
> [redacted]
>
> int main(){
> std::string str("Ni\xa4" "a"); // Niña

std::string str("Ni\0244a"); // as an alternative
> std::cout << str << std::endl;
> return 0;
> }
>

 
Reply With Quote
 
Jay Nabonne
Guest
Posts: n/a
 
      10-19-2005
On Tue, 18 Oct 2005 11:06:07 -0700, jalkadir wrote:

>
> Can someone please explain to me why, if I type 'Ni(ALT-164)A' at the
> windows prompt, I get '[c:\]Niña', but if my program does this:
> int main(){
> std::string str("Niña");


Try this:

1) At a command prompt, type:

echo Ni(ALT-164)A > foo.txt

2) Open foo.txt in your source code editor.

3) Now type the same sequence into your source code editor in the same
file. You will see two different characters.

4) Save the file back and close it.

5) If you're using Visual Studio, open the file in binary mode. Otherwise,
use Debug.

You'll see:

4e 69 a4 61 0d 0a
4e 69 f1 61 0d 0a

They're different characters...

Victor's suggestion looks like it will work.

- Jay

 
Reply With Quote
 
Zara
Guest
Posts: n/a
 
      10-19-2005
On 18 Oct 2005 11:10:25 -0700, "mlimber" <(E-Mail Removed)> wrote:

>jalkadir wrote:
>> Can someone please explain to me why, if I type 'Ni(ALT-164)A' at the
>> windows prompt, I get '[c:\]Niña', but if my program does this:
>> int main(){
>> std::string str("Niña");
>> std::cout << str << std::endl;
>> return 0;
>> }
>>
>> I get [C:\]Ni±a
>>
>> Can someone please, please, give me a hand understanding this
>> problem?!!
>>
>> TIA

>
>Perhaps different fonts are being used in the two windows?
>
>Cheers! --M


This is *Off-Topic*, as it is os-dependent, but the answer follows,
hope it helps.

I deduce from what you write that you are programming in MSWindows.

You are writing the program in some windows-based IDE, where the
charcater set is unicode and/or Windows-1252. In it, 'ñ' has the code
\xf1 and 'Ñ' has the code \xd1.

When you open a console, the character set is another really
different: it is the one that IBM devised for PC some decades ago, and
it is named somethiong like ASSCVII code page 437. In it, the codes
for 'ñ' and 'Ñ' are \xa4 and \xa5, respectively. This characetr set
may be seen at Start | All programs | Accessories | System tools |
Character set, and selecting Terminal font. Well, the exact location
and name of the tool may be slightly different, I am translating form
spanish.

So, you must use some especial means to convert from one code to the
other: either write the characters by escap seuqences, or use the MS
functions CharToOem and CharToOemBuff (serach at msdn.microsoft.com)

Saludos,

Zara
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help for Unicode char and Unicode char based string in Ruby Chirag Mistry Ruby 6 02-08-2008 12:45 PM
unicode wrap unicode object? ygao Python 6 04-08-2006 09:54 AM
HELP! HELP! PLEASE, PLEASE, PLEASE tpg comcntr Computer Support 11 02-15-2004 06:22 PM
please help... ...me learn C++ please please please :) KK C++ 2 10-14-2003 02:08 PM
Unicode + jsp + mysql + tomcat = unicode still not displaying Robert Mark Bram Java 0 09-28-2003 05:37 AM



Advertisments