错误 C1071:由于 #ifdeffed 原始字符串文字中的 /*,在注释中发现意外的文件结尾

jto*_*ker 5 c++ visual-studio

为什么此代码会出现“错误 C1071:在注释中发现意外的文件结尾”错误?

#include <iostream>

int main()
{
#if 0
   std::string script = R"(#!/bin/sh
ls /mnt/*.txt
)";
#endif
}
Run Code Online (Sandbox Code Playgroud)

我使用的是 Visual Studio 16.7.5。

jto*_*ker 3

这似乎是一个编译器错误。我已提交票证:https://developercommunity.visualstudio.com/t/Error-C1071 :-Unexpected-end-of-file-foun/1592300?entry=myfeedback

这是更多数据。 解决方法是不使用带有此字符序列的原始字符串文字。

#include <iostream>

// VS 16.7.5

int main()
{
#if 1
   std::string script = R"(#!/bin/sh
ls /ok/*.txt
)";
#endif

#if 0
   std::string script = R"(#!/bin/sh
ls /not_ok/*.txt
)";
#endif

#if 0
   std::string script = R"(#!/bin/sh
//ls /compiles_but_invalid_script/*.txt
)";
#endif

#if 0
   std::string script = "(#!/bin/sh\nls /and_this_is_ok/*.txt";
#endif
}
Run Code Online (Sandbox Code Playgroud)