std::ws - cppreference.com (original) (raw)

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:

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

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::ws might not construct the sentryobject (insonsistent with other input functions) required to constructthe sentry object

[edit] See also

| | extracts and discards characters until the given character is found (public member function of std::basic_istream<CharT,Traits>) [edit] | | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |