-
October 2nd, 2003, 05:34 AM
#1
is there a C++ IsNumeric function as in VB?
I'm looking fo a function that will act like IsNumeric at VB
meaning: Returns True if an expression can be evaluated as a number
-
October 2nd, 2003, 05:53 AM
#2
Short answer: No there isn't, but you could write your own (assuming you are talking about strings)
Long answer: Why do you need a function like that ? Many times in VB programmers tend to use strings for a host of different things, since it's a pain to define more appropriate data structures or I/O routines. I'd say that you probably don't need a function like this if you think about what your code should do and how it should be designed from a C++ point of view.
Get this small utility to do basic syntax highlighting in vBulletin forums (like Codeguru) easily.
Supports C++ and VB out of the box, but can be configured for other languages.
-
October 2nd, 2003, 05:58 AM
#3
well actually I do need this function
I'm getting a string from a server and need to know if it's numeric...
-
October 2nd, 2003, 06:43 AM
#4
How involved does the function have to be ? VBs IsNumeric is actually a bit more complex than it first appears, since it will recognize number formats dependent on the current thread locale. For example on an english system, IsNumeric("3,182,263.4746") will return True. If you need that kind of handling then have a look at GetNumberFormat in MSDN and work from there.
If your numbers are only composed of decimal digits (no decimal dot, no comma, no hexadecimal numbers, no Unicode numbers like arabic etc.), then it's much easier.
Get this small utility to do basic syntax highlighting in vBulletin forums (like Codeguru) easily.
Supports C++ and VB out of the box, but can be configured for other languages.
-
October 2nd, 2003, 09:59 AM
#5
what about this?
Code:
bool is_numeric( const std::string& s )
{
std::stringstream ss(s);
double d;
ss >> d;
return ss.good();
}
-
October 2nd, 2003, 11:30 AM
#6
Look at strtod, strtol and strtoul. If you use the endptr parameter then you might have a very simple way to do what you need to do.
-
October 5th, 2003, 01:20 AM
#7
mwilliamson
what is 'good' function?
-
October 5th, 2003, 03:51 AM
#8
is that enough or that there are more options for numeric value?
I don't have arabic numbers
bool IsNumeric(char ch)
{
if(ch >= '0' && ch <= '9')
return true;
return false;
}
-
October 5th, 2003, 04:21 AM
#9
Originally posted by avi123
what is 'good' function?
'good()' return true if the stream is okay (the goodbit is 'set')...
-
October 5th, 2003, 04:21 AM
#10
Originally posted by avi123
is that enough or that there are more options for numeric value?
I don't have arabic numbers
Well...that should be fine...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|