| | |
number format exceptions
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jul 2005
Posts: 164
Reputation:
Solved Threads: 5
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.
•
•
Join Date: Oct 2005
Posts: 3
Reputation:
Solved Threads: 0
•
•
•
•
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.
C++ Syntax (Toggle Plain Text)
try { fracNum = Integer.parseInt(JOptionPane.showInputDialog( Assign3.this,"Enter Numerator") ); fracDen = Integer.parseInt(JOptionPane.showInputDialog( Assign3.this,"Enter Denominator") ); frac.set( fracNum,fracDen ); myCQ.enqueue(frac);} 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).
•
•
Join Date: Jul 2005
Posts: 164
Reputation:
Solved Threads: 5
well in c++ you dont need to do that. you can get input like this....
C++ Syntax (Toggle Plain Text)
int an_int; while( ! cin>>an_int ) { // didnt get an int so deal with that here cin.clear(); // clear error flags cin.ignore(numeric_limits<streamsize>::max(),'\n'); // clear junk input from cin }
![]() |
Similar Threads
- Get the text with mouse hover (JavaScript / DHTML / AJAX)
- php number format (PHP)
- Finding a number in a line (Perl)
- WIn XP Crashes (Windows NT / 2000 / XP)
Other Threads in the C++ Forum
- Previous Thread: summation program
- Next Thread: Need help with while loop
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion count data database delete deploy desktop developer directshow dll dynamiccharacterarray email encryption error file forms fstream function functions game getline google graph homeworkhelp homeworkhelper iamthwee ifstream input int integer lib linkedlist linux list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates text tree unix url vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





