C++20 sections · 1024 units
Open in Course

The Whitespace Problem

Spaces terminate extraction

The extraction operator >> treats whitespace as a delimiter, not as part of the data. This works for single words but fails when you need to read phrases with spaces. If you ask for a full name using string fullName; cin >> fullName;, and the user types John Doe, you only get "John".

The space acts as a stop signal. This limitation exists because >> was designed for token-based parsing, where spaces separate distinct values. For reading entire lines including spaces, you need a different function.