cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : IOstream Library : manipulators : ws
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forum
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
IOstream Library
manipulators
classes:
· filebuf
· fstream
· ifstream
· ios
· iostream
· ios_base
· istream
· istringstream
· ofstream
· ostream
· ostringstream
· streambuf
· stringbuf
· stringstream
objects:
· cerr
· cin
· clog
· cout
types:
· fpos
· streamoff
· streampos
· streamsize
manipulators
· boolalpha
· dec
· endl
· ends
· fixed
· flush
· hex
· internal
· left
· noboolalpha
· noshowbase
· noshowpoint
· noshowpos
· noskipws
· nounitbuf
· nouppercase
· oct
· resetiosflags
· right
· scientific
· setbase
· setfill
· setiosflags
· setprecision
· setw
· showbase
· showpoint
· showpos
· skipws
· unitbuf
· uppercase
· ws

-

ws manipulator function
istream& ws ( istream& is );
<istream>

Extract whitespaces

Extracts as many whitespace characters as possible from the current position in the input sequence. The extraction stops as soon as a non-whitespace character is found. These whitespace characters extracted are not stored in any variable.

Notice that most istream objects have the skipws flag set by default, and therefore already skip all whitespaces before all extraction operations.

Parameters

is
Input stream object where to apply.
Because this function is a manipulator, it is designed to be used alone with no arguments in conjunction with the extraction (>>) operations on streams (see example below).

Return Value

The same stream object (is).

Example

// ws manipulator example
#include <iostream>
#include <sstream>
using namespace std;

int main () {
  char a[10], b[10];

  istringstream iss ("one \n \t two");
  iss >> noskipws;
  iss >> a >> ws >> b;
  cout << a << "," << b << endl;

  return 0;
}

Basic template declaration

template <class charT, class traits>
  basic_istream<charT,traits>& ws (basic_istream<charT,traits>& is);

See also

skipws Skip whitespaces (manipulator function)
noskipws Do not skip whitespaces (manipulator function)

© The C++ Resources Network, 2000-2007 - All rights reserved
Spotted an error? - contact us