This article focuses on discussing how to use cout for multi-line printing. This can be easily done using any of these two methods:
Let’s discuss each of these methods in detail.
Using endl
The endl statement can be used to print the multi-line string in a single cout statement. Below is the C++ program to show the same:
C++
#include <iostream>
using namespace std;
int main()
{
cout << " GeeksforGeeks is best"
" platform to learn " << endl << " It is used by"
" students to gain knowledge" <<
endl << " It is really helpful" ;
return 0;
}
|
Output
GeeksforGeeks is best platform to learn
It is used by students to gain knowledge
It is really helpful
Time complexity: O(1)
Auxiliary Space: O(1)
Using ‘\n’
‘\n’ can be used instead of endl to print multi-line strings. Below is the C++ program to implement the above approach:
C++
#include <iostream>
using namespace std;
int main()
{
cout << " GeeksforGeeks is best"
" platform to learn \n It"
" is used by students to"
" gain knowledge \n It is"
" really helpful" ;
return 0;
}
|
Output
GeeksforGeeks is best platform to learn
It is used by students to gain knowledge
It is really helpful
Time complexity: O(1)
Auxiliary Space: O(1)
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
23 Jul, 2022
Like Article
Save Article