How can I convert UNICODEwchar to ANSIC_char using STL.

R

recover

#include <xxx>
int main()
{
const wchar* pwcHello=L"hello";
char* pcHello;
xxxxxx //do something using stl
cout<<pcHello<<endl;
}

=============out===========
hello
====end out========

I know in Windows,I can use WideCharToMultiByte to convert wchar_t Encoding
in Unicode to char Encoding in ANSI .

How can I do this using STL?



--
= = = = = = = = = = = = = = = = = = = = = =

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ÖÂ
Àñ£¡

ÕÅÖ¾¸Õ
----------------------------
Co.: ±±¾©ÁéͼÐÇѶ¿Æ¼¼ÓÐÏÞ¹«Ë¾ Ñз¢²¿
Ad.: ±±¾©Êк£µíÇøÖйشåÈí¼þÔ°ººÍõ´óÏöþ²ãDÇø
ZIP£º 100094
Tel.: 010-82825800£­8006
Mobile:
Mail£º[email protected]
MSN: (e-mail address removed)
¹«Ë¾£º http://www.lingtu.com/
ÁéͼÔÚÏß:http://www.51ditu.com/
--------------------------
 
?

=?iso-8859-1?q?Kirit_S=E6lensminde?=

recover said:
#include <xxx>
int main()
{
const wchar* pwcHello=L"hello";
char* pcHello;
xxxxxx //do something using stl
cout<<pcHello<<endl;
}

=============out===========
hello
====end out========

I know in Windows,I can use WideCharToMultiByte to convert wchar_t Encoding
in Unicode to char Encoding in ANSI .

How can I do this using STL?

The facetious answer is to just take every other byte skipping the
first.

In order to do this with other strings though you need to understand
the character encodings in use.

You cannot convert an arbitrary string from Unicode to ASCII because
there are many more Unicode characters than there is room for in ASCII.
You can't always convert it to Shift_JIS and you can't always convert
it to TIS-620.

The simplest thing to do is to store tables of Unicode against other
encoding and go through that or to use a library like ICU
(International Components for Unicode) to do the conversions for you.

There aren't simple answers in any of this. The route that involves the
least learning is to just keep everything as Unicode strings - then you
only need to understand the different Unicode encodings. If you want to
convert to other narrow string formats then you need to learn about all
of these individually - or atleast learn a lot about the libraries that
help handle them.


K
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top