std::ws
From cppreference.com
 
 
 
 
 
 C++ 
 Feature test macros (C++20)
 Concepts library (C++20)
 Metaprogramming library (C++11)
 Ranges library (C++20)
 Filesystem library (C++17)
 Concurrency support library (C++11)
 Execution control library (C++26)
Input/output library 
 
 
 
 
 
 
 
 
 
 
 
 
 Print functions (C++23)
 Buffers
(C++23)
(C++98/26*)
(C++20)
 Streams
 Abstractions
 File I/O
 String I/O
 Array I/O
(C++23)
(C++23)
(C++23)
(C++98/26*)
(C++98/26*)
(C++98/26*)
 Synchronized Output
(C++20)
 Types
 Error category interface
(C++11)
(C++11)
Input/output manipulators 
 
 
 
Integer formatting Boolean formatting Field width and fill control Other formatting Whitespace processing 
 
 Output flushing 
 
 Status flags manipulation Time and money I/O Quoted manipulator 
 Floating-point formatting
(C++11)(C++11)
ws
(C++20)(C++20)
(C++14)
Defined in header 
 
 
<istream> 
 template< class CharT, class Traits >
std::basic_istream <CharT, Traits>& ws( std::basic_istream <CharT, Traits>& is );
 
 
std::basic_istream <CharT, Traits>& ws( std::basic_istream <CharT, Traits>& is );
Discards leading whitespace from an input stream.
Behaves as an UnformattedInputFunction, except that is.gcount() is not modified. After constructing and checking the sentry object, extracts characters from the stream and discards them until any one of the following conditions occurs:
-  end of file condition occurs in the input sequence (in which case the function calls setstate(eofbit) but does not set failbit; this does not apply if theeofbitis already set on is prior to the call tows, in which case the construction of the sentry object would setfailbit).
- the next available character c in the input sequence is not whitespace as determined by std::isspace (c, is.getloc()). The non-whitespace character is not extracted.
This is an input-only I/O manipulator, it may be called with an expression such as in >> std::ws for any in of type std::basic_istream .
[edit] Parameters
 is
 -
 reference to input stream
[edit] Return value
is (reference to the stream after extraction of consecutive whitespace).
[edit] Notes
If eofbit is set on the stream prior to the call, the construction of the sentry object will set failbit.
[edit] Example
Run this code
#include <iomanip> #include <iostream> #include <istream> #include <sstream> #include <string> int main() { for (const char* str : {" #1 test", "\t #2 test", "#3 test"}) { std::string line; std::getline (std::istringstream {str}, line); std::cout << "getline returns:\t" << std::quoted (line) << '\n'; std::istringstream iss{str}; std::getline (iss >> std::ws, line); std::cout << "ws + getline returns:\t" << std::quoted (line) << '\n'; } }
Output:
getline returns: " #1 test" ws + getline returns: "#1 test" getline returns: " #2 test" ws + getline returns: "#2 test" getline returns: "#3 test" ws + getline returns: "#3 test"
[edit] Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
| DR | Applied to | Behavior as published | Correct behavior | 
|---|---|---|---|
| LWG 415 | C++98 | calling std::wsmight not construct the sentryobject (insonsistent with other input functions) | required to construct the sentry object |