Solved

istream buffer

Posted on 1997-10-03
2
326 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

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…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

770 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