unicode or just ignorance? Help please

Discussion in 'C++' started by jalkadir, Oct 18, 2005.

  1. jalkadir

    jalkadir Guest

    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
     
    jalkadir, Oct 18, 2005
    #1
    1. Advertising

  2. jalkadir

    mlimber Guest

    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
     
    mlimber, Oct 18, 2005
    #2
    1. Advertising

  3. 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
     
    Victor Bazarov, Oct 18, 2005
    #3
  4. jalkadir

    red floyd Guest

    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;
    > }
    >
     
    red floyd, Oct 18, 2005
    #4
  5. jalkadir

    Jay Nabonne Guest

    [OT] Re: unicode or just ignorance? Help please

    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
     
    Jay Nabonne, Oct 19, 2005
    #5
  6. jalkadir

    Zara Guest

    On 18 Oct 2005 11:10:25 -0700, "mlimber" <> 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
     
    Zara, Oct 19, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mike Treseler
    Replies:
    3
    Views:
    2,393
  2. Rienk van der Scheer

    Re: Showing my ignorance of VHDL again...

    Rienk van der Scheer, Aug 4, 2003, in forum: VHDL
    Replies:
    0
    Views:
    915
    Rienk van der Scheer
    Aug 4, 2003
  3. Merennulli
    Replies:
    2
    Views:
    929
    Merennulli
    Mar 14, 2006
  4. Luc The Perverse

    Enigma (Or Programmer Ignorance)

    Luc The Perverse, Dec 27, 2005, in forum: Java
    Replies:
    3
    Views:
    619
  5. Brent White
    Replies:
    3
    Views:
    373
    Brent White
    Jul 13, 2007
Loading...

Share This Page