C++ ios Library - Skipws Function


Advertisements

Description

It is used to sets the skipws format flag for the str stream. When the skipws format flag is set, as many whitespace characters as necessary are read and discarded from the stream until a non-whitespace character is found before. This applies to every formatted input operation performed with operator>> on the stream.

Declaration

Following is the declaration for std::skipws function.

ios_base& skipws (ios_base& str);

Parameters

str − Stream object whose format flag is affected.

Return Value

It returns Argument str.

Exceptions

Basic guarantee − if an exception is thrown, str is in a valid state.

Data races

It modifies str. Concurrent access to the same stream object may cause data races.

Example

In below example explains about std::skipws function.

#include <iostream>
#include <sstream>

int main () {
   char a, b, c;

   std::istringstream iss ("  123");
   iss >> std::skipws >> a >> b >> c;
   std::cout << a << b << c << '\n';

   iss.seekg(0);
   iss >> std::noskipws >> a >> b >> c;
   std::cout << a << b << c << '\n';
   return 0;
}

Let us compile and run the above program, this will produce the following result −

123
  1
ios.htm
Advertisements