SysTutorials

Linux Manual Pages › Section 3

stdws(3)

std::ws - std::ws

Synopsis

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:

Parameters

is - reference to input stream

Return value

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

Notes

If eofbit is set on the stream prior to the call, the construction of the sentry object will set failbit.

Example

// Run this code

#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: &quot;" << line << "&quot;\n";
}

Output:

  ws + getline returns: "this is a test"

See also

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