basic_ifstream::ws

Provides inline style formatting.

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

The ws manipulator skips whitespace characters in input.

The this pointer is returned.

Listing: Example of basic_istream:: manipulator ws usage:
// The file ewl-test (where the number of blanks (and/or tabs) 
// is unknown) contains:

//       a          b    c

#include <iostream>

#include <fstream>

#include <cstdlib>

int main()

{

   char * inFileName = "ewl-test";

   ifstream in(inFileName);

   if (!in.is_open())

   {cout << "Couldn't open for input\n"; exit(1);}

   char ch;

   in.unsetf(ios::skipws);

   

   cout << "Does not skip whitespace\n|";

   while (1)

   {

      in >> ch; // does not skip white spaces

      if (in.good())

         cout << ch;

      else break;

   }

   cout << "|\n\n";

   

   //reset file position

   in.clear(); 

   in.seekg(0, ios::beg);

   

   cout << "Does skip whitespace\n|";

   while (1)

   {

      in >> ws >> ch;   // ignore white spaces

      

      if (in.good())

         cout << ch;

      else break;

   }

   cout << "|" << endl;

      

   

   in.close();

   return(0);

}

Result:

  Does not skip whitespace
  |          a             b    c|
  Does skip whitespace
  |abc|