Solved

istream buffer

Posted on 1997-10-03
2
319 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
Comment Utility
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
Comment Utility
Then can I use cin.flush() ?
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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.

772 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

10 Experts available now in Live!

Get 1:1 Help Now