【问题标题】:C++: multiline string literal with concatenation?C ++:带有连接的多行字符串文字?
【发布时间】:2017-06-24 06:15:24
【问题描述】:

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

#define theValue 1000

static std::string str = R"(

foo )" + theValue + R"( bar

)";

【问题讨论】:

    标签: c++ string variables multiline


    【解决方案1】:

    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
    
    )";
    

    在一般情况下,您需要strings 或可以隐式转换为string 的东西才能使用std::string 的连接运算符。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-08-08
      • 2014-12-03
      • 2016-08-06
      • 2014-08-12
      • 1970-01-01
      • 2010-11-11
      • 2020-06-04
      • 2014-04-01
      相关资源
      最近更新 更多