![]() |
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++
Output Enter long string with spaces: Hello, Geeks Welcome to GfG
You entered: Hello, Geeks Welcome to GfG
|
Reffered: https://www.geeksforgeeks.org
C++ |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 16 |