Skip to content

Commit ba4b318

Browse files
author
Colin Robertson
authored
Update char-wchar-t-char16-t-char32-t.md
Address issue #169 Fix dangling "Unicode is the" fragment. Expand explanation of types and where they are used.
1 parent 70fe40c commit ba4b318

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

docs/cpp/char-wchar-t-char16-t-char32-t.md

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,24 @@ manager: "ghogen"
1717
ms.workload: ["cplusplus"]
1818
---
1919
# char, wchar_t, char16_t, char32_t
20-
The types char, wchar_t, char16_t and char32_t are built in types that represent alphanumeric characters as well as non-alphanumeric glyphs and non-printing characters. char is eight bits in size, wchar_t and char16_t are 16 bits in size, and char32_t is 32 bits.
21-
22-
## Syntax
23-
20+
The types **char**, **wchar_t**, **char16_t** and **char32_t** are built-in types that represent alphanumeric characters as well as non-alphanumeric glyphs and non-printing characters.
21+
22+
## Syntax
23+
2424
```cpp
25-
char ch1{ 'a' };
26-
wchar_t ch2{ 'a' }; // or {L'a'}
27-
char16_t ch3{ L'a' };// or {L'a'}
28-
char32_t ch4{ L'a' };// or {L'a'}
25+
char ch1{ 'a' }; // or { u8'a' }
26+
wchar_t ch2{ L'a' };
27+
char16_t ch3{ u'a' };
28+
char32_t ch4{ U'a' };
2929
```
3030
31-
## Remarks
32-
The `char` type was the original character type in C and C++. It can be used to store characters from the ASCII character set or any of the ISO-8859 character sets, or the UTF-8 character set. The type `unsigned char` is often used to represent a *byte* which is not a built-in type in C++. The char type is not suitable for text in many languages. In general, modern programs should use one of the wide character types to represent text. Unicode is the
33-
34-
In the C++ standard library, the basic_string type is specialized for both narrow and wide strings. Use std::string when the characters are of type char, and std::wstring when the characters are of type wchar_t. Other types that represent text, including std::stringstream and std::cout have specializations for narrow and wide strings.
31+
## Remarks
32+
33+
The **char** type was the original character type in C and C++. The type **unsigned char** is often used to represent a *byte*, which is not a built-in type in C++. The **char** type can be used to store characters from the ASCII character set or any of the ISO-8859 character sets, and individual bytes of multi-byte characters such as Shift-JIS or the UTF-8 encoding of the Unicode character set. Strings of **char** type are referred to as *narrow* strings, even when used to encode multi-byte characters. In the Microsoft compiler, **char** is an 8-bit type.
34+
35+
The **wchar_t** type is an implementation-defined wide character type. In the Microsoft compiler, it represents a 16-bit wide character used to store Unicode encoded as UTF-16LE, the native character type on Windows operating systems. The wide character versions of the Universal C Runtime (UCRT) library functions use **wchar_t** and **wchar_t \*** types as parameters and return values, as do the wide character versions of the native Windows API.
36+
37+
The **char16_t** and **char32_t** types represent 16-bit and 32-bit wide characters, respectively. Unicode encoded as UTF-16 can be stored in the **char16_t** type, and Unicode encoded as UTF-32 can be stored in the **char32_t** type. Strings of these types and **wchar_t** are all referred to as *wide* strings, though the term often refers specifically to strings of **wchar_t** type.
38+
39+
In the C++ standard library, the `basic_string` type is specialized for both narrow and wide strings. Use `std::string` when the characters are of type **char**, `std::u16string` when the characters are of type **char16_t**, `std::u32string` when the characters are of type **char32_t**, and `std::wstring` when the characters are of type **wchar_t**. Other types that represent text, including `std::stringstream` and `std::cout` have specializations for narrow and wide strings.
3540

0 commit comments

Comments
 (0)