?
Solved

istream buffer

Posted on 1997-10-03
2
Medium Priority
?
337 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 1

Accepted Solution

by:
ohell earned 200 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses
Course of the Month10 days, 6 hours left to enroll

762 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