Re: How can I convert a ISO 8859-2 to UTF?
On Jan 23, 4:38 am, "focussedg...@gmail.com" <focussedg...@gmail.com>
wrote:
How can I convert a ISO 8859-2 to UTF?
How can I convert a ISO 8859-2 and ISO 8859-9 to UTF in c++?
Is there something similar in c++ as in Java ?
In Java we can simply create a new string(oldstring, "8859-2");
Is it that simple in c++?
No. The philosophy in C++ is that you use a single encoding
internally (say UTF-8), and do all of the code translation at
the system interface level (reading and writing); this is done
by imbuing an appropriate locale in the fstream doing the
reading or writing.
Of course, this philosophy falls down if you're reading or
writing from a socket, rather than a file. Either you have to
do the code translation in your streambuf, or on the byte buffer
you're working with. There is a facet, codecvt, which is
supposed to be used here (so we're back to locale), but I find
it anything but easy to use; in particular, it will not manage
the memory for you. (In your particular case, you can always
ensure a target buffer of six times the length when converting
8859-2 to UTF-8, and you're OK.) On many systems, there's also
an iconv function; as far as I can see, it doesn't do anything
the std::codecvt doesn't, but it may be easier to find the
necessary arguments than it is to find an appropriate locale.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34