| | |
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 binary c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game generator givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets





