![]() |
VOOZH | about |
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 spaces
Output: Input Entered: Hey! Geek Welcome to GfG
To take std::cin input with spaces we need to customize the behavior of the standard input stream by treating the newline character ('\n') as a delimiter in place of a space. To achieve this use the below approach:
Approach:
'\n') to be considered as a space character. cin.imbue() to set the locale of the std::cin with a new locale.The below program demonstrates how we can take std::cin input with spaces in C++.
Output
Enter Input with Spaces:
Hey! Geek Welcome to GfG
Input Entered: Hey! Geek Welcome to GfG