|
1 | 1 | ---
|
2 |
| -description: "Learn more about: /source-charset (Set Source Character Set)" |
3 |
| -title: "/source-charset (Set Source Character Set)" |
4 |
| -ms.date: "02/06/2019" |
| 2 | +description: "Learn more about: /source-charset (Set source character set)" |
| 3 | +title: "/source-charset (Set source character set)" |
| 4 | +ms.date: 01/31/2022 |
5 | 5 | f1_keywords: ["source-charset", "/source-charset"]
|
6 | 6 | helpviewer_keywords: ["/execution-charset compiler option"]
|
7 | 7 | ms.assetid: d3c5bf7f-526d-4ee4-acc5-c1a02a4fc481
|
8 | 8 | ---
|
9 |
| -# /source-charset (Set Source Character Set) |
| 9 | +# `/source-charset` (Set source character set) |
10 | 10 |
|
11 |
| -Lets you specify the source character set for your executable. |
| 11 | +This option lets you specify the source character set for your executable. |
12 | 12 |
|
13 | 13 | ## Syntax
|
14 | 14 |
|
15 |
| -``` |
16 |
| -/source-charset:[IANA_name|.CPID] |
17 |
| -``` |
| 15 | +> **`/source-charset:`**[*`IANA_name`* | *`.CPID`*] |
18 | 16 |
|
19 | 17 | ## Arguments
|
20 | 18 |
|
21 |
| -**IANA_name**<br/> |
| 19 | +*`IANA_name`*\ |
22 | 20 | The IANA-defined character set name.
|
23 | 21 |
|
24 |
| -**CPID**<br/> |
25 |
| -The code page identifier as a decimal number. |
| 22 | +*`.CPID`*\ |
| 23 | +The code page identifier as a decimal number, preceded by a `.` character. |
26 | 24 |
|
27 | 25 | ## Remarks
|
28 | 26 |
|
29 |
| -You can use the **/source-charset** option to specify an extended source character set to use when your source files include characters that are not represented in the basic source character set. The source character set is the encoding used to interpret the source text of your program into the internal representation used as input to the preprocessing phases before compilation. The internal representation is then converted to the execution character set to store string and character values in the executable. You can use either the IANA or ISO character set name, or a dot (.) followed by a 3 to 5 digit decimal code page identifier to specify the character set to use. For a list of supported code page identifiers and character set names, see [Code Page Identifiers](/windows/win32/Intl/code-page-identifiers). |
| 27 | +You can use the **`/source-charset`** option to specify an extended source character set to use when your source files include characters that are not represented in the basic source character set. The source character set is the encoding used to interpret the source text of your program. It's converted into the internal representation used as input to the preprocessing phases before compilation. The internal representation is then converted to the execution character set to store string and character values in the executable. You can use either the IANA or ISO character set name, or a dot (`.`) followed by 3-5 decimal digits that specify the code page identifier of the character set to use. For a list of supported code page identifiers and character set names, see [Code Page Identifiers](/windows/win32/Intl/code-page-identifiers). |
30 | 28 |
|
31 |
| -By default, Visual Studio detects a byte-order mark to determine if the source file is in an encoded Unicode format, for example, UTF-16 or UTF-8. If no byte-order mark is found, it assumes the source file is encoded using the current user code page, unless you specify a character set name or code page by using the **/source-charset** option. Visual Studio allows you to save your C++ source code by using any of several character encodings. For more information about source and execution character sets, see [Character Sets](../../cpp/character-sets.md) in the language documentation. |
| 29 | +By default, Visual Studio detects a byte-order mark to determine if the source file is in an encoded Unicode format, for example, UTF-16 or UTF-8. If no byte-order mark is found, it assumes that the source file is encoded in the current user code page, unless you use the **`/source-charset`** or **`/utf-8`** option to specify a character set name or code page. Visual Studio allows you to save your C++ source code in any of several character encodings. For more information about source and execution character sets, see [Character sets](../../cpp/character-sets.md) in the language documentation. |
32 | 30 |
|
33 |
| -The source character set you supply must map the 7-bit ASCII characters to the same code points in your character set, or many compilation errors are likely to follow. Your source character set must also be mappable to the extended Unicode character set encodable by UTF-8. Characters that are not encodable in UTF-8 are represented by an implementation-specific substitute. The Microsoft compiler uses a question mark for these characters. |
| 31 | +The source character set you supply must map the 7-bit ASCII characters to the same code points in your character set, or many compilation errors are likely to follow. Your source character set must also have a mapping to the extended Unicode character set of UTF-8. Characters that have no equivalent in UTF-8 are represented by an implementation-specific substitute. The Microsoft compiler uses a question mark for these characters. |
34 | 32 |
|
35 |
| -If you want to set both the source character set and the execution character set to UTF-8, you can use the **/utf-8** compiler option as a shortcut. It is equivalent to specifying **`/source-charset:utf-8 /execution-charset:utf-8`** on the command line. Any of these options also enables the **/validate-charset** option by default. |
| 33 | +If you want to set both the source character set and the execution character set to UTF-8, you can use the **`/utf-8`** compiler option as a shortcut. It's equivalent to **`/source-charset:utf-8 /execution-charset:utf-8`** on the command line. Any of these options also enables the **`/validate-charset`** option by default. |
36 | 34 |
|
37 | 35 | ### To set this compiler option in the Visual Studio development environment
|
38 | 36 |
|
39 |
| -1. Open the project's **Property Pages** dialog box. For details, see [Set C++ compiler and build properties in Visual Studio](../working-with-project-properties.md). |
| 37 | +1. Open the **Property Pages** dialog box for your project. For details, see [Set C++ compiler and build properties in Visual Studio](../working-with-project-properties.md). |
40 | 38 |
|
41 | 39 | 1. Select the **Configuration Properties** > **C/C++** > **Command Line** property page.
|
42 | 40 |
|
43 |
| -1. In **Additional Options**, add the *`/source-charset`* option, and specify your preferred encoding. |
| 41 | +1. In **Additional Options**, add the **`/source-charset`** option, and specify your preferred encoding. |
44 | 42 |
|
45 | 43 | 1. Choose **OK** to save your changes.
|
46 | 44 |
|
47 | 45 | ## See also
|
48 | 46 |
|
49 |
| -[MSVC Compiler Options](compiler-options.md)<br/> |
50 |
| -[MSVC Compiler Command-Line Syntax](compiler-command-line-syntax.md)<br/> |
51 |
| -[/execution-charset (Set Execution Character Set)](execution-charset-set-execution-character-set.md)<br/> |
52 |
| -[/utf-8 (Set source and execution character sets to UTF-8)](utf-8-set-source-and-executable-character-sets-to-utf-8.md)<br/> |
53 |
| -[/validate-charset (Validate for compatible characters)](validate-charset-validate-for-compatible-characters.md) |
| 47 | +[MSVC compiler options](compiler-options.md)\ |
| 48 | +[MSVC compiler command-line syntax](compiler-command-line-syntax.md)\ |
| 49 | +[`/execution-charset` (Set execution character set)](execution-charset-set-execution-character-set.md)\ |
| 50 | +[`/utf-8` (Set source and execution character sets to UTF-8)](utf-8-set-source-and-executable-character-sets-to-utf-8.md)\ |
| 51 | +[`/validate-charset` (Validate for compatible characters)](validate-charset-validate-for-compatible-characters.md) |
0 commit comments