Solved

istream buffer

Posted on 1997-10-03
2
324 Views
Last Modified: 2006-11-17
int n;
cin >> n;

As the above code, I have declarced an interger variables n.
I try to input the value of n by cin. However, when I try to input a chracter as the input prompt. An error occur. The value of n is not changed.
I know that I can detect the invalid input using the cin.good().... I also try to use the cin.ignore() to delete the invalid character input from istream but fail to do this. Then how can I do to flush the istram so that the character from istream?
0
Comment
Question by:matchz
2 Comments
 
LVL 1

Accepted Solution

by:
ohell earned 100 total points
ID: 1170802
Looks to me like you have an eof condition. you make sure that
cin.rdstate() & ~eofstate

If the eof is not true, you can flush the stream by cin.tie()->flush()

Hope this helps
0
 

Author Comment

by:matchz
ID: 1170803
Then can I use cin.flush() ?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now