Skip to content


Multi-line string literals in C/C++

Just a quick note, both are valid ways of defining multi-line string, the 1st way is probably preferred as you can indent your strings

const char* str1 = "This "
     "is"
  "a "
"sentence";

const char* str2 = "This \
is\
a \
sentence";

void main() {

printf("%s\n", str1);
printf("%s\n", str2);

}

Posted in C/C++. Tagged with , , .