VS检测源代码编码格式优先级如下:
- 默认情况下,Visual Studio 会检测文件开头的byte-order标记,以确定源文件是否采用Unicode 格式,例如 UTF-16 或 UTF-8.
- 如果编译选项指定
/utf-8或/source-charset选项指定了编码,按照编译选项为准。 - 如上两个都未找到,则假定源文件使用当前用户代码页(Code Page)中编码。
/utf-8 == /source-charset:utf-8 /execution-charset:utf-8
参考:/utf-8 (Set source and execution character sets to UTF-8) | Microsoft Learn
