| | |
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
Views: 3317 | Replies: 4
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays assignment based beginner binary c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer display dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multidimensional multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search sort sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets





