12

Possible Duplicate:
Unicode in C++

If I remembered correctly, the default character and string encoding in C++ are ASCII. Is there a simple way to enable Unicode support?

Community
  • 1
  • 1
segfault
  • 5,759
  • 9
  • 45
  • 66
  • @Troubadour: How do you create a link in a comment? – Afriza N. Arief Jun 08 '10 at 02:34
  • Well, simply copy pasting a URL will transform it in a link (though without giving you the opportunity to have a pretty title). As for this latter link: simply voting to close as duplicate will create the comment automatically :) – Matthieu M. Jun 08 '10 at 06:24
  • @afriza: Same way as do would in an answer. Click the question icon above the answer edit field to get help on how to create links. In this case, as @Matthieu M says, the comment at the top by me was actually auto-generated by SO. – Troubadour Jun 08 '10 at 10:13

4 Answers4

6

Current C++ doesn't specify encoding in any way. You might look into an actual Unicode library like ICU or, on some architectures and implementations you can use wchar_t to manipulate and hold Unicode strings.

Edit: This answer was referring to C++03. As noted, it doesn't apply any longer.

Edward Strange
  • 40,307
  • 7
  • 73
  • 125
  • 7
    It does now! [( 1 )](https://en.wikipedia.org/wiki/C%2B%2B11#New_string_literals) | [( 2 )](https://stackoverflow.com/questions/6796157/unicode-encoding-for-string-literals-in-c11) | [( 3 )](http://en.cppreference.com/w/cpp/language/string_literal) – Marc.2377 Jan 20 '17 at 20:21
3

It rather depends what you want to do with the text you are processing. Half the point of UTF-8 is that you don't need to change existing code if it handles 8-bit chars and does nothing special with characters above 128. Of course, strlen is the length in bytes rather than the character or code-point count. So it may be that you have a text in, text out program that can use UTF-8 directly. Or it may be that you're creating a GUI in text and so need to handle ruby and RTL text, in which case your job is much more complicated and you probably need to chose appropriate libraries.

Pete Kirkham
  • 48,893
  • 5
  • 92
  • 171
1

Depends on the version of C++ you are using. C++0x (not entirely released yet but still supported on many compilers) adds native UTF-8 support to the language. Otherwise, no the language does not support UTF-8. C++03 and earlier support unicode through the use of Wide Characters (wchar_t).

Billy ONeal
  • 104,103
  • 58
  • 317
  • 552
  • 4
    It's 2017 and C++ never added UTF8 support. It added UTF16 and UTF32 in the form of char16_t, u16string, char32_t and u32string. UTF8 data is still treated as char/string – Panagiotis Kanavos Nov 01 '17 at 11:09
-4

If u are using Visual Studio then going into the project properties and defining a Preprocessor as _UNICODE does the job for u.

Anuj
  • 389
  • 1
  • 5
  • 20