How to Take Multiple Line String Input in C++? Last Updated : 01 Feb, 2024 Comments Improve Suggest changes Like Article Like Report In C++, taking string input is a common practice but the cin is only able to read the input text till whitespace. In this article, we will discuss how to read the multiple line of text input in C++. For Example, Input:Enter Your Text: This is amultiline text.Output:You Have Entered:This is amultiline text.Reading Multiple Line String Input in C++ To read multiple lines of text input in C++, we can use the getline() function with a loop and a condition that states when you want to stop taking the input. While looping keep storing each line in a vector of string that can be used for processing later on. C++ Program to Read Multiple Lines of InputThe below example shows how to read muti-line string input in C++. C++ // C++ Program to Read Multiple Lines of Input #include <iostream> #include <string> #include <vector> using namespace std; int main() { // Declare variables string str; vector<string> s; // Prompt user to enter multiple lines of text cout << "Enter multiple lines of text: " << endl; // Read input lines until an empty line is encountered while (getline(cin, str)) { if (str.empty()) { break; } s.push_back(str); } // Display the entered lines cout << "You entered the following lines: " << endl; for (string& it : s) { cout << it << endl; } return 0; } Output Enter multiple lines of text: Hello! GeekWelcome to GeeksforGeeks Learn to codeYou entered the following lines: Hello! GeekWelcome to GeeksforGeeksLearn to code Comment More infoAdvertise with us Next Article How to Take Multiple Line String Input in C++? S surya9c5sb Follow Improve Article Tags : C++ Programs C++ cpp-input-output cpp-string CPP Examples +1 More Practice Tags : CPP Similar Reads How to Take Multiple String Inputs in a Single Line in C++? In C++, strings are used to store textual data. While working with user input, we often may need to take multiple string inputs in a single line only. In this article, we will learn how to take multiple string inputs in a single line. Example Input: Hi,Geek,Welcome,to,GfG delimiter = ',' Output: Str 2 min read How to Take Long String Input With Spaces in C++? In C++, we often take long strings with a lot of characters as inputs with spaces but if we use cin then our input gets terminated as soon as whitespace is encountered. In this article, we will discuss how to take long strings with spaces as input in C++. Take Long String Input With Spaces in C++To 2 min read How to Take Multiple Input from User in C++? In C++, we use cin when we want to take input from the user. We often also need to take more than one input at a time. In this article, we will learn how to take multiple inputs in C++. Take Multiple Inputs from a User in C++To take multiple inputs from users, we can repeatedly use the std::cin usin 2 min read How to Read Multiple Numbers from a Single Line of Input in C++? In C++, when working with user inputs we often need to take input of multiple numbers from a user in a single line. In this article, we will learn how to read multiple numbers from a single line of input in C++. Example Input: 1 7 0 4 6 8 Output: Entered Number: 1, 7, 0, 4, 6, 8Take Multiple Numbers 2 min read How to Handle Multiple String Inputs with Spaces in C++? In C++, strings are a sequence of characters that might contain spaces in many cases but we can read only the input text till whitespace using cin. In this article, we will learn how to handle multiple string inputs with spaces in C++. Example: Input:Enter multiple strings:String1String2Output:You E 2 min read Like