How to declare multiline string in C++

4 Answers

0 votes
#include <iostream>

int main() {
    std::string s = "C++ is a general-purpose programming language "
                    "created by Bjarne Stroustrup as an extension "
                    "of the C programming language, or \"C with Classes\"";

    std::cout << s;
}



/*
run:

C++ is a general-purpose programming language created by Bjarne Stroustrup as an extension of the C programming language, or "C with Classes"

*/

 



answered May 9, 2021 by avibootz
edited Feb 25, 2022 by avibootz
0 votes
#include <iostream>
  
int main() {
    std::string s = "C++ is a general-purpose programming language\n"
                    "created by Bjarne Stroustrup as an extension\n"
                    "of the C programming language, or \"C with Classes\"";
  
    std::cout << s;
}
  
  
  
  
/*
run:
  
C++ is a general-purpose programming language
created by Bjarne Stroustrup as an extension
of the C programming language, or "C with Classes"
  
*/

 



answered May 9, 2021 by avibootz
edited Feb 25, 2022 by avibootz
0 votes
#include <iostream>
 
int main() {
    const char* str = R"(Line1
Line2
Line3
Line4)";                    
 
    std::cout << str;
}
 
 
 
 
/*
run:
 
Line1
Line2
Line3
Line4
 
*/

 



answered Feb 25, 2022 by avibootz
edited Feb 1, 2023 by avibootz
0 votes
#include <iostream>

int main() {
    const char* str = "line1\n"
        "line2\n"
        "line3\n"
        "line4\n";

    std::cout << str;
}




/*
run:

line1
line2
line3
line4

*/

 



answered Feb 1, 2023 by avibootz
...