Something like print END << END; in C++?

后端 未结 8 1729

Is there anyway to do something like PHP\'s

print << END
yadayadayada
END;

in C++? (multi-line, unescaped, easy-to-cut-and-paste stre

8条回答
  •  南方客
    南方客 (楼主)
    2021-01-02 00:18

    C++11 has raw string literals:

    // this doesn't have '\n', but '\\' and 'n'
    R"(yada"yadayada\n)" 
    

    And if you need those parens, you can do that, too, using whatever you want for an end token:

    // the following will be "(yada)(yada)(yada)"
    R"END((yada)(yada)(yada))END" 
    

    it also works with embedded new lines:

    // the following will be "\n(yada)\n(yada)\n(yada)\n"
    R"END(
    (yada)
    (yada)
    (yada)
    )END" 
    

提交回复
热议问题