How to Read a Line of Input Text in C++? Last Updated : 01 Feb, 2024 Comments Improve Suggest changes Like Article Like Report In C++, we often need to take input from the user by reading an input text line by line but the cin method only takes input till whilespace. In this article, we will look at how to read a full line of input in C++. For Example, Input: This is a text.Output: Entered Text: This is a text.Taking a Line of Input Text in C++To read the complete line of text from the input stream, we can use the inbuilt function std::getline() that takes the input until either the end of input is reached or cin signals an error. The std::getline() function is specially used to read lines of input from the stream. C++ Program to Read a Line of Input Text C++ // C++ program to read a line of input text #include <iostream> #include <string> using namespace std; int main() { // Declare a string to store the input string input; // Prompt the user to enter a line of text cout << "Enter a line of text: "; // Use getline() to read a line of text and store it in // the 'input' variable getline(cin, input); // Display the input cout << "You entered: " << input << endl; return 0; } Output Enter a line of text: Hey! geek welcome to gfgYou entered: Hey! geek welcome to gfgNote: By default, the delimiter is a new line('\n') but we can also provide other delimiters that we want as a third parameter to the getline function. Comment More infoAdvertise with us Next Article How to Read a Line of Input Text in C++? V vaishali_patel Follow Improve Article Tags : C++ Programs C++ cpp-input-output CPP Examples Practice Tags : CPP Similar Reads How to Take Operator as Input in C++? Operators are symbols that specify some kind of operation. In C++, we sometimes need to take operators as user input mainly to perform mathematical operations. In this article, we will learn how to take operators as user input in C++. Operators as Input in C++To take operators (like +,-,*,/ etc) as 2 min read How to Read a File Line by Line in C++? In C++, we can read the data of the file for different purposes such as processing text-based data, configuration files, or log files. In this article, we'll learn how to read a file line by line in C++. Read a File Line by Line in C++We can use the std::getline() function to read the input line by 2 min read How to Take Multiple Line String Input in C++? 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 amultilin 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 Read Input Until EOF in C++? In C++, EOF stands for End Of File, and reading till EOF (end of file) means reading input until it reaches the end i.e. end of file. In this article, we will discuss how to read the input till the EOF in C++. Read File Till EOF in C++The getline() function can be used to read a line in C++. We can 2 min read Like