How to Take Long String Input With Spaces in C++? Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report 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 take a long string input with whitespace we can use repeatedly getline() function using which we can read an entire line along with spaces in a single go until the user presses enter which indicates that the input is finished. C++ Program to Take Long String Input With SpacesThe below example uses a getline() function to read the entire line of input, ensuring that spaces are included. C++ // C++ program to take long string input with spaces. #include <iostream> #include <string> using namespace std; int main() { // prompt user to enter string cout << "Enter long string with spaces: "; // declare a string to store the user input string usr_str; // Use getline() to take input with spaces getline(cin, usr_str); // Display the input cout << "You entered: " << usr_str << endl; return 0; } Output Enter long string with spaces: Hello, Geeks Welcome to GfG You entered: Hello, Geeks Welcome to GfG Comment More infoAdvertise with us Next Article How to Take Long String Input With Spaces in C++? S sourabhcao9e0 Follow Improve Article Tags : C++ Programs C++ cpp-input-output cpp-string CPP Examples +1 More Practice Tags : CPP Similar Reads How to Take std::cin Input with Spaces? In C++, std::cin is used to accept the input from the standard input device. By default, the delimiter used by std::cin to separate input is a whitespace. In this article, we will learn how to take std::cin input with spaces in C++. Example: Input: Hey! Geek Welcome to GfG //input with spacesOutput: 2 min read How to Use stringstream for Input With Spaces in C++? In C++, the std::stringstream class is a stream class to operate on strings and is very useful when we want to operate on a string as if it were a stream (like cin or cout). In this article, we will learn how to use string streams for input with spaces in C++.Example:Input: string = âHello, World!âO 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 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 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 Like