String litterals (c++)

Can a std::string contain embedded nulls? - yes

Raw string literals c++11

This is the closest to Ruby Heredoc

const char * vogon_poem = R"V0G0N(
             O freddled gruntbuggly thy micturations are to me
                 As plured gabbleblochits on a lurgid bee.
              Groop, I implore thee my foonting turlingdromes.   
           And hooptiously drangle me with crinkly bindlewurdles,
Or I will rend thee in the gobberwarts with my blurlecruncheon, see if I don't.

                (by Prostetnic Vogon Jeltz; see p. 56/57)
)V0G0N";

older solution, for a one line string

std::string multiline_str =
    "Line 1 "
    "Line 2 "
    "Line 3";

or with a macro / SO. It will replace any number of consecutive whitespace characters by a single space

#define MULTILINE_STRING(...) #__VA_ARGS__

 std::string multiline_str = MULTILINE_STRING(
      I love getting my doubts solved 
      by the help of Delft Stack Tutorials.);

see also

std::string("\0world", 6);
s.append("\0world", 6);
Written on September 19, 2020, Last update on September 9, 2023
c++ string