Skip to content

Instantly share code, notes, and snippets.

@Lokno
Last active August 28, 2022 10:08
Show Gist options
  • Save Lokno/b0f9ee0b802d8be78fb79e70a3db52eb to your computer and use it in GitHub Desktop.
Save Lokno/b0f9ee0b802d8be78fb79e70a3db52eb to your computer and use it in GitHub Desktop.
Some methods of printing multiline strings in C++
#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;
}
@Spllit1
Copy link

Spllit1 commented Aug 28, 2022

Thanks! Very helpful 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment