473,395 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

unicode or just ignorance? Help please

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
5 1427
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: Gerson Kurz | last post by:
AAAAAAAARG I hate the way python handles unicode. Here is a nice problem for y'all to enjoy: say you have a variable thats unicode directory = u"c:\temp" Its unicode not because you want it...
1
by: krammer | last post by:
Hello, I have the following questions that I have not been able to find any *good* answers for. Your help would me much appreciated!, fyi, I am a Java XML guy and I have no experience with SGML...
4
by: webdev | last post by:
lo all, some of the questions i'll ask below have most certainly been discussed already, i just hope someone's kind enough to answer them again to help me out.. so i started a python 2.3...
2
by: Neil Schemenauer | last post by:
python-dev@python.org.] The PEP has been rewritten based on a suggestion by Guido to change str() rather than adding a new built-in function. Based on my testing, I believe the idea is...
32
by: Wolfgang Draxinger | last post by:
I understand that it is perfectly possible to store UTF-8 strings in a std::string, however doing so can cause some implicaions. E.g. you can't count the amount of characters by length() | size()....
1
by: PvdK | last post by:
Hello, Although a lot of postings in the past discuss the subject of A2000 and Unicode support, I couldn't find what I was looking for. My institute is compiling a dictionary of early middle...
7
by: Csaba Gabor | last post by:
If I do alert(encodeURI(String.fromCharCode(250))); (in FF 1.5+ or IE6 on my winXP Pro) then I get: %C3%BA Now I was sort of expecting something like %u... (and a single (4 digit?) unicode hex...
3
by: Terry Hancock | last post by:
I still run into my own ignorance a lot with unicode in Python. Is it possible to define some combination of __repr__, __str__, and/or __unicode__ so that the unicode() wrapper isn't necessary...
24
by: Donn Ingle | last post by:
Hello, I hope someone can illuminate this situation for me. Here's the nutshell: 1. On start I call locale.setlocale(locale.LC_ALL,''), the getlocale. 2. If this returns "C" or anything...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.