number format exceptions

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2005
Posts: 3
Reputation: frank_hfc is an unknown quantity at this point 
Solved Threads: 0
frank_hfc frank_hfc is offline Offline
Newbie Poster

number format exceptions

 
0
  #1
Oct 3rd, 2005
is there an exception type in c++ like the NumberFormatException in java? i'm looking to use a try/catch to do type checking after a cin input from the user.
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 3
Reputation: frank_hfc is an unknown quantity at this point 
Solved Threads: 0
frank_hfc frank_hfc is offline Offline
Newbie Poster

Re: number format exceptions

 
0
  #2
Oct 4th, 2005
... spent another hour searching for this type of exception and nothing has turned up. any takers?
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 164
Reputation: Stoned_coder is an unknown quantity at this point 
Solved Threads: 5
Stoned_coder Stoned_coder is offline Offline
Junior Poster

Re: number format exceptions

 
0
  #3
Oct 4th, 2005
perhaps if you explain better what you are trying to do. maybe a small code sample. Why would you need to type check after a cin.
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 3
Reputation: frank_hfc is an unknown quantity at this point 
Solved Threads: 0
frank_hfc frank_hfc is offline Offline
Newbie Poster

Re: number format exceptions

 
0
  #4
Oct 4th, 2005
Originally Posted by Stoned_coder
perhaps if you explain better what you are trying to do. maybe a small code sample. Why would you need to type check after a cin.
here's what i'm familiar with doing in java:

  1. try
  2. {
  3. fracNum = Integer.parseInt(JOptionPane.showInputDialog( Assign3.this,"Enter Numerator") );
  4. fracDen = Integer.parseInt(JOptionPane.showInputDialog( Assign3.this,"Enter Denominator") );
  5. frac.set( fracNum,fracDen );
  6. myCQ.enqueue(frac);}
  7.  
  8. catch ( NumberFormatException n ) {JOptionPane.showMessageDialog( Assign3.this,("Please enter an integer."));}

what i'm looking for in c++ is to make sure the input from the user is only a number (float specifically).
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 164
Reputation: Stoned_coder is an unknown quantity at this point 
Solved Threads: 5
Stoned_coder Stoned_coder is offline Offline
Junior Poster

Re: number format exceptions

 
0
  #5
Oct 4th, 2005
well in c++ you dont need to do that. you can get input like this....
  1. int an_int;
  2. while( ! cin>>an_int )
  3. {
  4. // didnt get an int so deal with that here
  5. cin.clear(); // clear error flags
  6. cin.ignore(numeric_limits<streamsize>::max(),'\n'); // clear junk input from cin
  7. }
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC