std::ws - cppreference.com

##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# std::ws

From cppreference.com
< cpp‎ | io‎ | manip

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:

- end of file condition occurs in the input sequence (in which case the function calls setstate(eofbit) but does not set `failbit`.

- 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] Example

Run this code

    #include <iostream>
    #include <sstream>

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

Output:

    ws + getline returns: "this is a test"

### [edit] See also

ignore | extracts and discards characters until the given character is found (public member function of `std::basic_istream`) [edit]

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/io/manip/ws&oldid=66423"