[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

cin>>overflow

Posted on 1997-10-13
2
Medium Priority
?
354 Views
Last Modified: 2006-11-17
int Getvalue(double& d)
{

 //Flush clears the input buffer and resets error flags
 //Max and Mix resp 1-999
//Question how do i prevent an overflow
//eg.
//assign d 99999999999999999999999999999999999999999
//get an execption error?

inline void  Flush(istream& str)
{
      str.clear();
      int  char_to_skip =
            str.rdbuf()->in_avail();
   
       str.ignore(char_to_skip);
}

 Flush(cin);
 while(!(cin>>d).gcount()<4){

         if(!cin||d<Min||d>Max)
            cout<<endl<<"Invalid input!"<<endl<<"ReEnter Value: ";
    else break;

       Flush(cin);
     if(cin.eof())
        return 0;
 }
 return(1);
}
0
Comment
Question by:sigjas
2 Comments
 
LVL 3

Accepted Solution

by:
eugenem earned 400 total points
ID: 1171231
Read from cin not to a double but to string. Than convert this string to double (on this step you can perform any checks).
0
 

Author Comment

by:sigjas
ID: 1171232
Thank you
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

834 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