How to Take Multiple Line String Input in C++? Last Updated : 23 Jul, 2025 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 Create Quiz Comment S surya9c5sb Follow 0 Improve S surya9c5sb Follow 0 Improve Article Tags : C++ Programs C++ cpp-input-output cpp-string CPP Examples +1 More Explore C++ BasicsIntroduction to C++3 min readData Types in C++6 min readVariables in C++4 min readOperators in C++9 min readBasic Input / Output in C++3 min readControl flow statements in Programming15+ min readLoops in C++7 min readFunctions in C++8 min readArrays in C++8 min readCore ConceptsPointers and References in C++5 min readnew and delete Operators in C++ For Dynamic Memory5 min readTemplates in C++8 min readStructures, Unions and Enumerations in C++3 min readException Handling in C++12 min readFile Handling in C++8 min readMultithreading in C++8 min readNamespace in C++5 min readOOP in C++Object Oriented Programming in C++8 min readInheritance in C++6 min readPolymorphism in C++5 min readEncapsulation in C++3 min readAbstraction in C++4 min readStandard Template Library(STL)Standard Template Library (STL) in C++3 min readContainers in C++ STL2 min readIterators in C++ STL10 min readC++ STL Algorithm Library3 min readPractice & ProblemsC++ Interview Questions and Answers1 min readC++ Programming Examples4 min read Like