Link to home
Start Free TrialLog in
Avatar of x25
x25

asked on

Flush IO Stream

i have function as follows:

void func()
{
   char   a;

  .........

   cout << "Enter: ";
   cin >> a;
   .........

}

 However, on the next iteration of cin >> a, a would have the value of '\n'
which was entered in the first place. Someone told me to flush the io stream on each iteration. How ?
ASKER CERTIFIED SOLUTION
Avatar of efn
efn

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of x25
x25

ASKER

i remember using bdflush() in C. is there anything similar ?
bdflush is a Linux thing, not a C thing.  If your program is to run under Linux, you can use bdflush in C++ as well as in C.  But since it has to do with flushing buffers to disk, I don't think it would help you with a cin input stream.
Avatar of x25

ASKER

cin.ignore() works fine.
Thanks, it is now accepting the input using cin.ignore. BUT my Customer Search runs into a problem now.

When I enter a customer number, it will find it, display the Customer No. but then the ERROR below pops up:

An Access Violation (Segmentation Fault) Raised in your program
Sorry, wrong question!! :-)