1

How to convert string from one charset to another in C++ in a portable way? For example I want to convert to wstring to UTF-8 character array or . How to do this?

I am asking some standard way no chilkatsoft, wxWidgets, Qt. Its a plain C++ application. Though some simple class or methods will do the job.

asked Nov 16, 2009 at 11:02
4
  • Your solution is only going to be as portable as the libraries you use (ICU is very portable, for example). If you insist on using no libraries at all, you should be prepared to copy lookup tables with thousands and thousands of entries. Commented Nov 16, 2009 at 11:19
  • utf-16 and utf-8 are both different encodings of the same underlying numbers, so its quite possible to do this transformation in a very small platform independent way. For everything else, lots of character encodings only make sense or are defined on a single platform, this is one of those places where it makes sense to have a file - or files - with platform specific character set transformation routines. Commented Nov 16, 2009 at 11:56
  • Hello priyank Regard Anirudha Gupta anirudhagupta.blogspot.com Commented Nov 17, 2009 at 10:55
  • I am anirudha you can contact me @ anirudhagupta.blogspot.com/2009/11/…. but don't disclosed your mail address in comment Commented Nov 17, 2009 at 11:25

3 Answers 3

3

The common repetoire for character sets is Unicode. Hence, you'd want a Unicode-oriented library. Frameworks like Qt and wxWidgets offer some of this functionality; ICU is more specific to Unicode text processing.

answered Nov 16, 2009 at 11:09
Sign up to request clarification or add additional context in comments.

3 Comments

I am asking in standard C++, you should know the baggage of wxWidgets or Qt.
The implied prerequisite is: there is no functionality for conversions between character sets in c++.
Indeed. And the reason that there is "baggage" in those libraries is because there's so much possible with computers, most of which isn't standardized by ISO. One mans bagage is another mans essential function.
1

The Boost Serialization library contains a UTF-8 codecvt facet.

answered Nov 16, 2009 at 11:28

Comments

1

You can use libiconv (Google it ), it supports many encodings.

answered Nov 16, 2009 at 11:53

1 Comment

how portable libiconv is? and is there any samples?

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.