Defined in header <istream> | ||
---|---|---|
template< class CharT, class Traits > 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:
setstate(eofbit)
but does not set failbit
; this does not apply if the eofbit
is already set on is
prior to the call to ws
, in which case the construction of the sentry object would set failbit
). 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
.
is | - | reference to input stream |
is
(reference to the stream after extraction of consecutive whitespace).
If eofbit
is set on the stream prior to the call, the construction of the sentry object will set failbit
.
#include <iostream> #include <istream> #include <sstream> #include <string> int main() { std::istringstream s(" this is a test"); std::string line; std::getline(s >> std::ws, line); std::cout << "ws + getline returns: \"" << line << "\"\n"; }
Output:
ws + getline returns: "this is a test"
extracts and discards characters until the given character is found (public member function of std::basic_istream<CharT,Traits> ) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
http://en.cppreference.com/w/cpp/io/manip/ws