recover wrote:
Quote:
#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