Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 treats it as being in native encoding. Code editor, however, does not have this problem.

warning C4819: The file contains a character that cannot be represented in the current code page (932). Save the file in Unicode format to prevent data loss

Is there a fix for this behavior? I remember this being common problem in all visual studio versions, but I don't remember ever seeing a fix. I can't exactly keep adding bom marks to every file that is not mine, especially if source is maintained in code repository.

like image 393
SigTerm Avatar asked Nov 01 '22 12:11

SigTerm


1 Answers

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

like image 132
Mark Tolonen Avatar answered Nov 16 '22 06:11

Mark Tolonen