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

后端 未结 8 1725

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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-01 23:59

    Yes. http://en.cppreference.com/w/cpp/language/string_literal

    const char* s1 = R"foo(
    Hello
    World
    )foo";
    //same as
    const char* s2 = "\nHello\nWorld\n";
    

    Whether or not it's best-practice, C++11 does pretty well exactly what you want.

提交回复
热议问题