C++: Is there a standard definition for end-of-line in a multi-line string constant?

后端 未结 3 1357
Happy的楠姐
Happy的楠姐 2021-01-07 18:04

If I have a multi-line string C++11 string constant such as

R\"\"\"line 1
line 2
line3\"\"\"

Is it defined what character(s) the line termi

3条回答
  •  粉色の甜心
    2021-01-07 18:45

    The standard seems to indicate that:

    R"""line 1
    line 2
    line3"""
    

    is equivalent to:

    "line 1\nline 2\nline3"
    

    From 2.14.5 String literals of the C++11 standard:

    4 [ Note: A source-file new-line in a raw string literal results in a new-line in the resulting execution string literal. Assuming no whitespace at the beginning of lines in the following example, the assert will succeed:

    const char *p = R"(a\
    b
    c)";
    assert(std::strcmp(p, "a\\\nb\nc") == 0);
    

    end note ]

    5 [ Example: The raw string

    R"a(
    )\
    a"
    )a"
    

    is equivalent to "\n)\\\na\"\n".

提交回复
热议问题