C++:带连接的多行字符串文字?

C++: multiline string literal with concatenation?

如何定义可以与其他变量连接的多行原始字符串文字?以下不编译:

#define theValue 1000

static std::string str = R"(

foo )" + theValue + R"( bar

)";

std::to_string should help you out with this one

#define theValue 1000

static std::string str = R"(

foo )" + std::to_string(theValue) + R"( bar

)";

在一般情况下,您需要 string 或可以隐式转换为 string 的内容,以便使用 std::string 的连接运算符。