warning c4819 in Visual Studio C++ 2013 express - utf8 files without bom

后端 未结 4 1115
慢半拍i
慢半拍i 2021-01-03 03:39

In visual studio C++ 2013 express it seems that unless utf8-encoded file has BOM mark, compiler fails to understand that the file being compiled is in UTF8 encoding and trea

相关标签:
4条回答
  • 2021-01-03 03:48

    Update to Visual Studio 2015. It supports new compiler options for source and execution characters sets.

    You can use the /utf-8 option to specify both the source and execution character sets as encoded by using UTF-8. 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....

    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 have specified a code page by using /utf-8 or the /source-charset option. Visual Studio allows you to save your C++ source code by using any of several character encodings....

    Ref: https://msdn.microsoft.com/en-us/library/mt708821.aspx

    0 讨论(0)
  • 2021-01-03 03:49

    How should the compiler guess which encoding you intend the file to be interpreted with? That said, there are a few options:

    • Why not simply add a BOM? It's a pretty good way to mark a UTF-8 file, as it is very unlikely to be misinterpreted.
    • Other than that, I believe you can use a #pragma to tell MSC about the encoding, although I never used this myself.
    • Lastly, not using anything outside the basic character set is also an option which is slightly outdated in our world but still works reliable.
    0 讨论(0)
  • 2021-01-03 04:00

    To the date I have not encountered any solution to the problem.

    If a fix for this behavior exists, apparently it is well guarded secret.

    0 讨论(0)
  • 2021-01-03 04:01

    If your system locale is not English (E.g. Chinese or other language), a simple way to fix this is to change your system setting of 'Region and Language' to be English. Just follow steps below:

    Control Panel -> Clock,Language,and Region -> Region and Language -> 
    Administrative -> Language for non-Unicode programs -> Change system locale.
    

    Is that simple? It fixes my problem as my system locale is Chinese. The description of 'Language for non-Unicode programs' is clear:

    This setting (system locale) controls the language used when displaying 
    text in programs that do not support Unicode.
    

    More details in the image

    I met this problem when I tried to build my project on Windows, which is successful on another Windows machine. I was crazy to modify all non-Unicode characters (All of then are comments) and so that compiler could move on. But there are too many files with this problem.

    0 讨论(0)
提交回复
热议问题