Name
ws function — Skips whitespace manipulator
Synopsis
template <class charT, class traits>
basic_istream<charT,traits>& ws(basic_istream<charT,traits>& stream);
The ws
function is an input
stream manipulator that skips whitespace characters in stream
using the same technique as
basic_istream::sentry
. If the
manipulator reaches the end-of-file, it sets eofbit
, but not failbit
.
Example
Suppose you want to read a line of text by calling getline
, but you also want to skip
whitespace at the beginning of the line. (Because getline
is an unformatted input function,
it does not automatically skip whitespace.) The following example
shows one way to skip whitespace and read the line using ws
:
char buffer[BUFSIZ]; . . . in >> ws; in.getline(buffer, sizeof(buffer));
Get C++ In a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.