Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using UNICODE character values in C++

Tags:

c++

unicode

How do you use unicode in C++ ? Im aware of wchar_t and wchar_t* but I want to know how you can assign value using only Unicode Values, similar to the way a character can be assigned by equating the variable to the ASCII value:

char a = 92;

Im uysing the MinGW compiler, if it makes a difference.

like image 477
viraj Avatar asked Sep 27 '11 15:09

viraj


People also ask

Can you use Unicode in C?

It can represent all 1,114,112 Unicode characters. Most C code that deals with strings on a byte-by-byte basis still works, since UTF-8 is fully compatible with 7-bit ASCII. Characters usually require fewer than four bytes. String sort order is preserved.

How do you write C in Unicode?

Unicode Character “C” (U+0043)

Does C use Unicode or ASCII?

As far as I know, the standard C's char data type is ASCII, 1 byte (8 bits).

What is ASCII code and Unicode explain how they are used in C language?

Unicode is the universal character encoding used to process, store and facilitate the interchange of text data in any language while ASCII is used for the representation of text such as symbols, letters, digits, etc. in computers. ASCII : It is a character encoding standard for electronic communication.


1 Answers

It can be as simple as:

wchar_t a=L'a';
wchar_t hello_world[]=L"Hello World";

// Or if you really want it to be (old school) C++ and not C

std::wstring s(L"Hello World");

// Or if you want to (be bleeding edge and) use C++11

std::u16string s16(u"Hello World");
std::u32string s32(U"Hello World for the ∞ᵗʰ time");
like image 88
Michael Goldshteyn Avatar answered Oct 30 '22 19:10

Michael Goldshteyn