std::ws

From Cppreference

< cpp | io | manip
Jump to: navigation, search
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.

First, constructs a std::basic_istream::sentry object with noskipws set to true. Afterwards, if good()==false, calls setstate(failbit) and returns. Otherwise, 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.

Contents

[edit] Parameters

is - reference to input stream

[edit] Return value

is (reference to the stream after extraction of consecutive whitespace)

[edit] Example

#include <iostream>
#include <sstream>
int main()
{
    std::istringstream s("     this is a test");
    std::string line;
    s >> std::ws;
    getline(s, line);
    std::cout << "ws + getline returns: \"" << line << "\"\n";
}

Output:

ws + getline returns: "this is a test"

[edit] See also

extracts and discards characters until the given character is found
(public member function of std::basic_istream)