问题遇到的现象和发生背景
用的是vs code,是一个新手,在C++ primer plus上看到了原始字符串,但是自己却无法操作,很迷茫,呜呜~~~
问题相关代码,请勿粘贴截图
#include <iostream>
using std::cout;
using std::endl;
int main()
{
cout << "I print \'\\\', \"\\n\" as I like." << endl;
cout << R"(I print '\', "\n" as I like.)" << endl;
cout << R"(I print '\',
"\n" as I like.)" << endl;
cout << R"haha(I print '\', "\n" and )" as I like.)haha" << endl;
}
运行结果及报错内容
try9.cpp:10:14: error: expected ';' after expression
cout << R"(I print '', "\n" as I like.)" << endl;
^
;
try9.cpp:10:13: error: use of undeclared identifier 'R'
cout << R"(I print '', "\n" as I like.)" << endl;
^
try9.cpp:10:30: error: expected ';' after expression
cout << R"(I print '', "\n" as I like.)" << endl;
^
;
try9.cpp:10:14: warning: expression result unused [-Wunused-value]
cout << R"(I print '', "\n" as I like.)" << endl;
^~~~~~~~~~~~~~~~
try9.cpp:10:30: error: expected expression
cout << R"(I print '', "\n" as I like.)" << endl;
^
try9.cpp:11:14: warning: missing terminating '"' character [-Winvalid-pp-token]
cout << R"(I print '',
^
try9.cpp:11:14: error: expected ';' after expression
cout << R"(I print '',
^
;
try9.cpp:11:13: error: use of undeclared identifier 'R'
cout << R"(I print '',
^
try9.cpp:11:14: error: expected expression
cout << R"(I print '',
^
try9.cpp:12:25: warning: missing terminating '"' character [-Winvalid-pp-token]
"\n" as I like.)" << endl;
^
try9.cpp:13:60: warning: missing terminating '"' character [-Winvalid-pp-token]
cout << R"haha(I print '', "\n" and )" as I like.)haha" << endl;
^
4 warnings and 7 errors generated.
我的解答思路和尝试过的方法
试着改了一下C++的版本,试了C++11以及更高的C++20,但是没有用。
我想要达到的结果
呜呜呜~~~怎么才能正常运行呢,本小白要疯了。呜呜呜~~~