Printing Output in Multiple Lines in C++ Last Updated : 23 Jul, 2022 Comments Improve Suggest changes Like Article Like Report This article focuses on discussing how to use cout for multi-line printing. This can be easily done using any of these two methods: Using endl.Using \n. 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++ // C++ program to show endl statement // can be used to print the multi-line // string in a single cout statement #include <iostream> using namespace std; // Driver code 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++ // C++ program to show '\n' can be // used instead of endl to print // multi-line strings #include <iostream> using namespace std; // Driver code 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; } //Main key points here are : //You can write as many statements as you want in a single line, //but I recommend you to write one statement per line to keep the code neat and clean. //Anything which is written between double quotation " " is a string literal. 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) Comment More infoAdvertise with us Next Article Printing Output in Multiple Lines in C++ R raunakkr819 Follow Improve Article Tags : C++ Practice Tags : CPP Similar Reads How to write long strings in Multi-lines C/C++? Image a situation where we want to use or print a long long string in C or C++, how to do this? In C/C++, we can break a string at any point in the middle using two double quotes in the middle. Below is a simple example to demonstrate the same. C #include<stdio.h> int main() { // We can put tw 2 min read Line Splicing in C/C++ While writing a program, sometimes we give comment about the working of the code in the comment section with the help of single/double comment line. But we had never thought that if at the end of this comment line if we use \(backslash) character then what will happen?The answer of the above questio 2 min read Basic Input / Output in C++ In C++, input and output are performed in the form of a sequence of bytes or more commonly known as streams.Input Stream: If the direction of flow of bytes is from the device (for example, Keyboard) to the main memory then this process is called input.Output Stream: If the direction of flow of bytes 5 min read std::string::insert() in C++ In C++, the string insert() function is used to insert characters or a string at the given position of the string. For example,C++#include <bits/stdc++.h> using namespace std; int main() { string s = "Geeks"; // Inserting another string at the friend // of s s.insert(s.size(), "forGeeks"); cou 4 min read Output of C++ programs | Set 34 (File Handling) What task does the following program perform? CPP #include<iostream> #include<fstream> using namespace std; int main() { ofstream ofile; ofile.open ("text.txt"); ofile << "geeksforgeeks" << endl; cout << "Data written to file" << endl 3 min read getline (string) in C++ The C++ getline() is a standard library function that is used to read a string or a line from an input stream. It extracts the characters from the input stream and appends it to the given string object until the delimiting character is encountered.Example:C++#include <bits/stdc++.h> using name 3 min read iswprint() in C/C++ with Examples The iswprint() is a built-in function in C/C++ which checks if the given wide character can be printed or not. It is defined within the cwctype header file of C++. By default, the following characters are printable: Digits (0 to 9)Uppercase letters (A to Z)Lowercase letters (a to z)Punctuation chara 2 min read Print 2D matrix in different lines and without curly braces in C/C++? Following is a general way of printing 2D matrix such that every row is printed in separate lines. C for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { cout << arr[i][j] << " "; } // Newline for new row cout << endl; } How to print without using any curly b 2 min read Reading Lines by Lines From a File to a Vector in C++ STL Prerequisites: STL in C++Vector in C++File handling in C++ The Standard Template Library (STL) is a set of C++ template classes to provide common programming data structures and functions such as lists, stacks, arrays, etc. It is a library of container classes, algorithms, and iterators. Vector in C 2 min read How to Print String Literal and Qstring With Qdebug in C++? Printing string literals and QString with QDebug in C++ can be a useful tool for debugging. By printing out the contents of a string or QString, you can quickly identify any issues that may be present in your code. In this article, weâll discuss how to print string literals and QString with QDebug i 2 min read Like