您的位置:首页 > 其它

VS2013,fatal error C1071: unexpected end of file found in comment

2016-05-15 15:49 459 查看
又是文件编码的问题,

我在编译程序时,出现了“fatal error C1071: unexpected end of file found in comment”错误,最后发现,是VS2013识别文件编码的问题,现在将其抽象出来。

我的代码如下:



编译后,有如下警告和错误:

1>------ Rebuild All started: Project: vc_test_code, Configuration: Debug Win32 ------
1>  Source.cpp
1>e:\vc_test_code\source.cpp : warning C4819: The file contains a character that cannot be represented in the current code page (936). Save the file in Unicode format to prevent data loss
1>e:\vc_test_code\source.cpp(17): fatal error C1071: unexpected end of file found in comment
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
可以发现,有一个警告,和一个致命的错误,

警告告诉我们:这个文件(source.cpp)包含了一个字符,这个字符在当前代码页无法被表达。以Unicode格式保存这个文件以防止数据丢失。

就是说,VS解析这个文件时,可能会出现错误。

然后,这个文件在UF8格式下,是这样的,



这个文件在ANSI格式下,是这样的。我们可以看到,多行注释符/**/没有结束。编译器也是这样认为的,所以编译器报错了。



结论:如果你的VS报了一个(一些)错误,但是这个错误无论如何用肉眼也找不到,那么有可能是VS识别文件编码的问题,你可以查看所有的“warning C4819: The file contains a character that cannot be represented in the current code page (936). Save the file in Unicode format to prevent data loss”相关的文件,问题可能出现在这些文件上。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: