c语言 error c2001,Visual Studio error C2001:常量中有换行符(解决办法)

在Visual Studio自动生成的项目中,碰见了一件关于文件编码的问题,集中在类似于以下的语句上:

DASLog (DASProtWarn, L"(%s)消息超时,进入慢循环召唤模式。", GetHierarchyName());

编译时会出现以下错误:

error C2001:常量中有换行符

该错误的原因很显然是文件编码的问题,在网上搜索了一下,找到了如下解决办法:

(1)全部用英文编码,不要用中文

(2)偶数中文 或 结尾加英文的符号,如"."

(3)将文件编码进行一个手动(如记事本)转换,改成UTF-8格式

我采用了第二种方式,直接将末尾的中文“。”改成了英文的“.”,该错误就解决了!

有个叫wva的人遇到过类似问题,他向微软提交了此bug

http://connect.microsoft.com/VisualStudio/feedback/details/341454/compile-error-with-source-file-containing-utf8-strings-in-cjk-system-locale

根据Visual C++ Compiler Team员工的解释:

The compiler when faced with a source file that does not have a BOM the compiler reads ahead a certain distance into the file to see if it can detect any Unicode characters - it specifically looks for UTF- and UTF-16

你可能感兴趣的:(c语言,error,c2001)