How to turn a char array into UTF-8?

Asked

Viewed 74 times

1

For example, I have a char cadeia[300];. I put characters in it, now I want to turn it into UTF-8.

  • Take a look at this link http://stackoverflow.com/questions/2573834/c-convert-string-or-char-to-wstring-or-wchar-t

  • Take a look at [tour]. You can accept an answer if it solved your problem. You can vote on every post on the site as well. Did any help you more? You need something to be improved?

1 answer

1

Don’t even try this.

Strings with any encoding multibyte are hard to manipulate. Unless you really want to venture into something very laborious, grab a library ready to manipulate this type of data. You can use the ICU, can use the type wstring if your compiler supports.

So if you use this, and you need to strings without being UTF-8, use the type string.

If you use these guys, you don’t have to use char * or char[]. We highly recommend doing this.

If you really have a legacy code that uses char *, can create a string wide thus:

wstring wcadeia(cadeia);
  • Depending on the platform, iconv is a way to convert between different encodings in C

Browser other questions tagged

You are not signed in. Login or sign up in order to post.