|
||||||
| C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||||
|
I only want a user to input numbers - does C++ have some sort of try-catch? I came across isdigit(), but I believe that is to check whether a character is a number. I came up with this that works excellent to check if a string contains all numbers
cpp Code:
But once its done, its still a string and I cant use it to perform math operations on. Can I cast it to an integer? Is there a better way to accomplish this?
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum | My Blog Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall |
| Sponsored Links |
|
|
|
|||
|
you can use sprintf function to cast string to an integer.
__________________
http://www.upredsun.com **Easily and automatically build tcp-based or udp-based network protocol source code** |
|
|||
|
C++ has try catch yes but it isn't used all that much (people prefer C style return values).
C++ Code:
You can throw just about any type. Java exceptions are generally just glorified strings, you could just throw a string in C++. |
|
|||
|
C++ Code:
Last edited by dargueta; 01-22-2008 at 11:40 PM. Reason: Forgot a function |
| Sponsored Links |
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
| WingedPanther | ........ | 2753.6 |
| Xav | ........ | 2704 |
| Brandon W | ........ | 1702.32 |
| John | ........ | 1207.73 |
| marwex89 | ........ | 1175.24 |
| morefood2001 | ........ | 966.05 |
| dcs | ........ | 655.75 |
| Steve.L | ........ | 475.59 |
| orjan | ........ | 418.58 |
| Aereshaa | ........ | 383.54 |