By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,649 Members | 1,808 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,649 IT Pros & Developers. It's quick & easy.

unicode or just ignorance? Help please

P: n/a
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

Oct 18 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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

Oct 18 '05 #2

P: n/a
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
Oct 18 '05 #3

P: n/a
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;
}

Oct 18 '05 #4

P: n/a
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

Oct 19 '05 #5

P: n/a
On 18 Oct 2005 11:10:25 -0700, "mlimber" <ml*****@gmail.com> 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
Oct 19 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.