basic_istream::sync

Synchronizes input and output

  int sync();
  
Remarks

This function attempts to make the input source consistent with the stream being extracted.

If rdbuf()->pubsync() returns -1 setstate(badbit) is called and traits::eof is returned.

Return

If rdbuf() is Null returns -1 otherwise returns zero.

Listing: Example of basic_istream::sync() usage:
// The file ewl-test contains:
// This functions attempts to make the input source 

// consistent with the stream being extracted.

// --

// CodeWarrior "Software at Work"

#include <iostream>

#include <fstream> 

#include <cstdlib>

char inFile[] = "ewl-test";

int main()

{ 

using namespace std;

   ifstream in(inFile);

   if(!in.is_open()) 

      {cout << "could not open file"; exit(1);}

   char str[10];

   if(in.sync())      // return 0 if successful

      { cout << "cannot sync"; exit(1); } 

   while (in.good())

   {

      in.get(str, 10, EOF);

      cout <<str; 

   }

   return 0;

} 

Result:

  This functions attempts to make the input source 
  consistent with the stream being extracted.
  --
  CodeWarrior "Software at Work"