|
2 | 2 | description: "Learn more about: How to: Convert Between Various String Types" |
3 | 3 | title: "How to: Convert Between Various String Types" |
4 | 4 | ms.custom: "get-started-article" |
5 | | -ms.date: 05/04/2022 |
| 5 | +ms.date: 05/09/2022 |
6 | 6 | helpviewer_keywords: ["converting string types", "string conversion [C++]", "strings [C++], converting"] |
7 | 7 | --- |
8 | 8 | # How to: Convert between various string types |
@@ -40,7 +40,7 @@ The `/clr` switch conflicts with some compiler switches that are set when you cr |
40 | 40 |
|
41 | 41 | ### Description |
42 | 42 |
|
43 | | -This example demonstrates how to convert from a `char *` to the string types listed above. A `char *` string (also known as a C-style string) uses a null character to indicate the end of the string. C-style strings usually require 1 byte per character, but can also use 2 bytes. In the examples below, `char *` strings are sometimes referred to as multibyte character strings because of the string data that results from converting from wide Unicode strings. Single byte and multibyte character (`MBCS`) functions can operate on `char *` strings. |
| 43 | +This example demonstrates how to convert from a `char *` to the string types listed above. A `char *` string (also known as a C-style string) uses a terminating null to indicate the end of the string. C-style strings usually require 1 byte per character, but can also use 2 bytes. In the examples below, `char *` strings are sometimes referred to as multibyte character strings because of the string data that results from converting from wide Unicode strings. Single byte and multibyte character (`MBCS`) functions can operate on `char *` strings. |
44 | 44 |
|
45 | 45 | For information about running and debugging this example, see [Run the examples](#run-the-examples). |
46 | 46 |
|
@@ -267,7 +267,7 @@ Hello, World! (System::String) |
267 | 267 |
|
268 | 268 | ### Description |
269 | 269 |
|
270 | | -This example demonstrates how to convert from a `_bstr_t` to other string types. The `_bstr_t` object encapsulates wide character `BSTR` strings. A `BSTR` string has a length value and doesn't use a null character to terminate the string, but the string type you convert to may require a terminating `NULL`. |
| 270 | +This example demonstrates how to convert from a `_bstr_t` to other string types. The `_bstr_t` object encapsulates wide character `BSTR` strings. A `BSTR` string has a length value and doesn't use a null character to terminate the string, but the string type you convert to may require a terminating null character. |
271 | 271 |
|
272 | 272 | For information about running and debugging this example, see [Run the examples](#run-the-examples). |
273 | 273 | ### Code |
@@ -296,7 +296,7 @@ int main() |
296 | 296 |
|
297 | 297 | // Convert the wide character _bstr_t string to a C-style |
298 | 298 | // string. To be safe, allocate two bytes for each character |
299 | | - // in the char* string, including the terminating NULL. |
| 299 | + // in the char* string, including the terminating null. |
300 | 300 | const size_t newsize = (orig.length() + 1) * 2; |
301 | 301 | char* nstring = new char[newsize]; |
302 | 302 |
|
@@ -368,7 +368,7 @@ Hello, World! (System::String) |
368 | 368 |
|
369 | 369 | ### Description |
370 | 370 |
|
371 | | -This example demonstrates how to convert from a `CComBSTR` to other string types. Like `_bstr_t`, a `CComBSTR` object encapsulates wide character `BSTR` strings. A `BSTR` string has a length value and doesn't use a null character to terminate the string, but the string type you convert to may require a terminating `NULL`. |
| 371 | +This example demonstrates how to convert from a `CComBSTR` to other string types. Like `_bstr_t`, a `CComBSTR` object encapsulates wide character `BSTR` strings. A `BSTR` string has a length value and doesn't use a null character to terminate the string, but the string type you convert to may require a terminating null. |
372 | 372 |
|
373 | 373 | For information about running and debugging this example, see [Run the examples](#run-the-examples). |
374 | 374 |
|
@@ -403,7 +403,7 @@ int main() |
403 | 403 | // Convert a wide character CComBSTR string to a |
404 | 404 | // regular multibyte char* string. Allocate enough space |
405 | 405 | // in the new string for the largest possible result, |
406 | | - // including space for a terminating NULL. |
| 406 | + // including space for a terminating null. |
407 | 407 | const size_t newsize = (orig.Length() + 1) * 2; |
408 | 408 | char* nstring = new char[newsize]; |
409 | 409 |
|
@@ -657,7 +657,7 @@ int main() |
657 | 657 |
|
658 | 658 | // Convert a wide character basic_string string to a multibyte char* |
659 | 659 | // string. To be safe, we allocate two bytes for each character |
660 | | - // in the original string, including the terminating NULL. |
| 660 | + // in the original string, including the terminating null. |
661 | 661 | const size_t newsize = (orig.size() + 1) * 2; |
662 | 662 |
|
663 | 663 | char* nstring = new char[newsize]; |
@@ -765,7 +765,7 @@ int main() |
765 | 765 | // Make a copy of the System::String as a multibyte |
766 | 766 | // char* string. Allocate two bytes in the multibyte |
767 | 767 | // output string for every wide character in the input |
768 | | - // string, including space for a terminating NULL. |
| 768 | + // string, including space for a terminating null. |
769 | 769 | size_t origsize = wcslen(wch) + 1; |
770 | 770 | const size_t newsize = origsize * 2; |
771 | 771 | size_t convertedChars = 0; |
|
0 commit comments