Last active
August 28, 2022 10:08
-
-
Save Lokno/b0f9ee0b802d8be78fb79e70a3db52eb to your computer and use it in GitHub Desktop.
Some methods of printing multiline strings in C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
using namespace std; | |
int main() | |
{ | |
// you could cascade operators | |
cout << "+---------+" << endl | |
<< "| |" << endl | |
<< "| THIS |" << endl | |
<< "| |" << endl | |
<< "+---------+" << endl; | |
// or use this syntax to declare a multiline string | |
// (the compiler concatenates the lines) | |
cout << | |
"+---------+\n" | |
"| |\n" | |
"| OR THIS |\n" | |
"| |\n" | |
"+---------+\n"; | |
// Or use an array and a loop | |
string box[] = { | |
"+---------+", | |
"| OR |", | |
"| EVEN |", | |
"| THIS |", | |
"+---------+", | |
"END"}; // tells the loop when to terminate | |
int i = 0; | |
while( box[i] != "END" ) | |
{ | |
cout << box[i++] << endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks! Very helpful 👍