By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,040 Members | 1,054 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,040 IT Pros & Developers. It's quick & easy.

isnumeric

P: n/a
Hello,

I would like to know if the function IsNumeric requires a header like
#include <iostream> to be functionnal

thanks

ken
Jul 22 '05 #1
Share this Question
Share on Google+
14 Replies


P: n/a
On Wed, 2 Jun 2004 21:26:56 -0400, "Kenny" <le******@yah00.c0m> wrote:
Hello,

I would like to know if the function IsNumeric requires a header like
#include <iostream> to be functionnal


There's no function by that name in either the C or C++ libraries.
Actually, I don't know of /any/ standard library functions whatsoever that
have capital letters in their names.

If you're asking about the character classification functions such as
isdigit(), isalpha(), et. al., then for C++ you should include <cctype>.
-leor

--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: download BD Software's free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html
Jul 22 '05 #2

P: n/a
that did not work ,
do you know the parameter setting of that calling function ?

K
Jul 22 '05 #3

P: n/a
Kenny wrote:

that did not work ,
do you know the parameter setting of that calling function ?


Kenny. Please make it a habit of yours to *not* post:
'It doesn't work'

Tell us *what* the problem is: Do you get a compiler
error? Do you get a runtime error? Does the program not
behave the way you want it to?

Also: post a small code snippet such that we can see what
you have tried and what gave you troubles. Ideally you post
a small, *complete* program, such that we can cut&paste
it into our development environments and try the very
same as you did.

If you don't do this then all that is left to us is: guess
And guessing is never a good way to figure out technical
problems.

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 22 '05 #4

P: n/a
Kenny. Please make it a habit of yours to *not* post:
'It doesn't work'

Tell us *what* the problem is: Do you get a compiler
error? Do you get a runtime error? Does the program not
behave the way you want it to?

Also: post a small code snippet such that we can see what
you have tried and what gave you troubles. Ideally you post
a small, *complete* program, such that we can cut&paste
it into our development environments and try the very
same as you did.

If you don't do this then all that is left to us is: guess
And guessing is never a good way to figure out technical
problems.

ok here is the code

cout << " Your choice please: ";
cin >> choice;
if (isnumeric(choice) == true){


Jul 22 '05 #5

P: n/a
Kenny wrote:
that did not work ,
do you know the parameter setting of that calling function ?

K


#include <iostream> // for cout
#include <cstdlib> // for EXIT_SUCCESS
#include <ctypes> // for isdigit

using std::cout;
using std::endl;
using std::isdigit;

int main(void)
{
cout << "Is '5' a digit (numeric)?" << endl;
cout << isdigit('5') << endl;
cout << "\nIs 'Z' a digit?" << endl;
cout << isdigit('Z') << endl;
return EXIT_SUCCESS;
}

Much can be learned by reading a C++ reference book
and the FAQ.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book

Jul 22 '05 #6

P: n/a
On Thu, 3 Jun 2004 09:27:31 -0400, "Kenny" <le******@yah00.c0m> wrote:
ok here is the code

cout << " Your choice please: ";
cin >> choice;
if (isnumeric(choice) == true){


Are you just inventing function names and hoping they work? Start with a
library reference of some kind, and examine your options. Here's one I
found in 30 seconds of Googling ("C library"):
http://www.acm.uiuc.edu/webmonkeys/book/c_guide/

-leor


--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: download BD Software's free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html
Jul 22 '05 #7

P: n/a

ok here is the code

cout << " Your choice please: ";
cin >> choice;
if (isnumeric(choice) == true){


Are you just inventing function names and hoping they work? Start with a
library reference of some kind, and examine your options. Here's one I
found in 30 seconds of Googling ("C library"):
http://www.acm.uiuc.edu/webmonkeys/book/c_guide/


I guess you did not try the term 'isnumeric' in google I just did not
find a page where it was talking about how to call it in c++, just VB and
C#.

Jul 22 '05 #8

P: n/a

"Thomas Matthews" <Th****************************@sbcglobal.net> wrote in
message news:eU*****************@newssvr33.news.prodigy.co m...
Kenny wrote:
that did not work ,
do you know the parameter setting of that calling function ?

K


#include <iostream> // for cout
#include <cstdlib> // for EXIT_SUCCESS
#include <ctypes> // for isdigit

using std::cout;
using std::endl;
using std::isdigit;

int main(void)
{
cout << "Is '5' a digit (numeric)?" << endl;
cout << isdigit('5') << endl;
cout << "\nIs 'Z' a digit?" << endl;
cout << isdigit('Z') << endl;
return EXIT_SUCCESS;
}

Much can be learned by reading a C++ reference book
and the FAQ.

I guess my book from Walter Savitch , absolute c++ is not so good.

Jul 22 '05 #9

P: n/a
Kenny wrote:
Kenny. Please make it a habit of yours to *not* post:
'It doesn't work'

Tell us *what* the problem is: Do you get a compiler
error? Do you get a runtime error? Does the program not
behave the way you want it to?

Also: post a small code snippet such that we can see what
you have tried and what gave you troubles. Ideally you post
a small, *complete* program, such that we can cut&paste
it into our development environments and try the very
same as you did.

If you don't do this then all that is left to us is: guess
And guessing is never a good way to figure out technical
problems.

ok here is the code

cout << " Your choice please: ";
cin >> choice;
if (isnumeric(choice) == true){


OK.
And what is the problem with this code?

Note: isnumeric() isn't one of the standard functions
So you must have written it by yourself. What this
function exactly has to look like is dependent on the
data type of choice.

So what is choice?
Where is the implementation of isnumeric()?
and last but not least: Which error message did you
get from your compiler.
Could it be that you wanted isdigit() instead of isnumeric()
(Note: isdigit() checks a *single* character if it represents
a numerical digit, not a whole string. But using this function
it is easy to write a function isNumeric which does the whole
thing on a complete string).
I know all of this may sound childish to you. But remember:
*You* sit in front of your computer. *You* write the program.
*You* see the error messages from your compiler. If we try
to help you, we can only use what *you* tell us. If you
call your doctor and cry: "Help" I am sure your doctor would
do the very same: Ask for details. If you are a good patient
you wouldn't let your doctor ask you for everything but provide
him with all you know about your problem in the first place.
We *want* to help you, that's why we are here and answer questions.
But we also expect people seeking for help to coorporate.

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 22 '05 #10

P: n/a
Kenny wrote:
>
ok here is the code

cout << " Your choice please: ";
cin >> choice;
if (isnumeric(choice) == true){


Are you just inventing function names and hoping they work? Start with a
library reference of some kind, and examine your options. Here's one I
found in 30 seconds of Googling ("C library"):
http://www.acm.uiuc.edu/webmonkeys/book/c_guide/


I guess you did not try the term 'isnumeric' in google I just did not
find a page where it was talking about how to call it in c++, just VB and
C#.


AS Leor has pointer out already, there is *no* function called
isnumeric() in standard C or standard C++.
Depending on what you actually want you have to
* use isdigit() out of the box
* write your own function isnumeric()

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 22 '05 #11

P: n/a
On Thu, 3 Jun 2004 09:57:17 -0400, "Kenny" <le******@yah00.c0m> wrote:
>>
>ok here is the code
>
> cout << " Your choice please: ";
> cin >> choice;
> if (isnumeric(choice) == true){
>
Are you just inventing function names and hoping they work? Start with a
library reference of some kind, and examine your options. Here's one I
found in 30 seconds of Googling ("C library"):
http://www.acm.uiuc.edu/webmonkeys/book/c_guide/


I guess you did not try the term 'isnumeric' in google


You guess wrong.
I just did not
find a page where it was talking about how to call it in c++, just VB and
C#.
Hello!!
-leor



--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: download BD Software's free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html
Jul 22 '05 #12

P: n/a

"Karl Heinz Buchegger" <kb******@gascad.at> wrote in message
news:40***************@gascad.at...
Kenny wrote:
Kenny. Please make it a habit of yours to *not* post:
'It doesn't work'

Tell us *what* the problem is: Do you get a compiler
error? Do you get a runtime error? Does the program not
behave the way you want it to?

Also: post a small code snippet such that we can see what
you have tried and what gave you troubles. Ideally you post
a small, *complete* program, such that we can cut&paste
it into our development environments and try the very
same as you did.

If you don't do this then all that is left to us is: guess
And guessing is never a good way to figure out technical
problems.

ok here is the code

cout << " Your choice please: ";
cin >> choice;
if (isnumeric(choice) == true){


OK.
And what is the problem with this code?

Note: isnumeric() isn't one of the standard functions
So you must have written it by yourself. What this
function exactly has to look like is dependent on the
data type of choice.

So what is choice?
Where is the implementation of isnumeric()?
and last but not least: Which error message did you
get from your compiler.
Could it be that you wanted isdigit() instead of isnumeric()
(Note: isdigit() checks a *single* character if it represents
a numerical digit, not a whole string. But using this function
it is easy to write a function isNumeric which does the whole
thing on a complete string).
I know all of this may sound childish to you. But remember:
*You* sit in front of your computer. *You* write the program.
*You* see the error messages from your compiler. If we try
to help you, we can only use what *you* tell us. If you
call your doctor and cry: "Help" I am sure your doctor would
do the very same: Ask for details. If you are a good patient
you wouldn't let your doctor ask you for everything but provide
him with all you know about your problem in the first place.
We *want* to help you, that's why we are here and answer questions.
But we also expect people seeking for help to coorporate.

Choice is an int, I read somewhere that isnumeric is a built in function ,
just like strcpy . Is numeric should return true if it is a numeric value
and false other wise. so isnumeric is not in c++ , just in c ??

K

Jul 22 '05 #13

P: n/a
Kenny wrote:

"Karl Heinz Buchegger" <kb******@gascad.at> wrote in message
news:40***************@gascad.at...
Kenny wrote:

> Kenny. Please make it a habit of yours to *not* post:
> 'It doesn't work'
>
> Tell us *what* the problem is: Do you get a compiler
> error? Do you get a runtime error? Does the program not
> behave the way you want it to?
>
> Also: post a small code snippet such that we can see what
> you have tried and what gave you troubles. Ideally you post
> a small, *complete* program, such that we can cut&paste
> it into our development environments and try the very
> same as you did.
>
> If you don't do this then all that is left to us is: guess
> And guessing is never a good way to figure out technical
> problems.
>
ok here is the code

cout << " Your choice please: ";
cin >> choice;
if (isnumeric(choice) == true){
OK.
And what is the problem with this code?

Note: isnumeric() isn't one of the standard functions
So you must have written it by yourself. What this
function exactly has to look like is dependent on the
data type of choice.

So what is choice?
Where is the implementation of isnumeric()?
and last but not least: Which error message did you
get from your compiler.
Could it be that you wanted isdigit() instead of isnumeric()
(Note: isdigit() checks a *single* character if it represents
a numerical digit, not a whole string. But using this function
it is easy to write a function isNumeric which does the whole
thing on a complete string).
I know all of this may sound childish to you. But remember:
*You* sit in front of your computer. *You* write the program.
*You* see the error messages from your compiler. If we try
to help you, we can only use what *you* tell us. If you
call your doctor and cry: "Help" I am sure your doctor would
do the very same: Ask for details. If you are a good patient
you wouldn't let your doctor ask you for everything but provide
him with all you know about your problem in the first place.
We *want* to help you, that's why we are here and answer questions.
But we also expect people seeking for help to coorporate.


Choice is an int,


Then I am afraid: What you want to do cannot be done.
An int holds a number per definition! That's what it is for.
I read somewhere that isnumeric is a built in function ,
just like strcpy . Is numeric should return true if it is a numeric value
and false other wise. so isnumeric is not in c++ , just in c ??


Not even there.
An int always holds a number! That's the definition of int. You can't
store "Hello world" in an int.

What you *want* to do is something completely different:
You want to check the users input if the user entered a number.
Well if you use

int choice;

cin >> choice;

Then the user has no other possibility: He *has* to enter a number
or otherwise the input stream would simply refuse to accept the
users input and go into a fail state.

There are 2 possibilities you can cope with that problem:
* detect that the stream has gone into a fail state, clear
that fail state and discard all pending input

* Don't read into an int. Read into a string instead. This
way the user can enter what he wants, a string can accept
everything. Then your part begins. You have to check if
what the user has entered is what you expected him to enter
and react accordingly.

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 22 '05 #14

P: n/a
Kenny wrote:

[snip]
Choice is an int, I read somewhere that isnumeric is a built in function ,
just like strcpy . Is numeric should return true if it is a numeric value
and false other wise. so isnumeric is not in c++ , just in c ??

K


Sorry Kenny, but isnumeric is not in C either.

Check your book carefully. Many authors write primitive
functions in other chapters and reference them throughout
the book.

The easiest method to test if an input value is numeric,
is to use the extraction operator, ">>" and read into
an integral (i.e. unsigned or signed integer) variable.
If the stream state is good, then the value is numeric.

Here is a common idiom:
unsigned int option_num;
do
{
// Display numeric options,
// such as 1. Do Something.
cout.flush(); // For synchronization.
cin >> option_num;
} while (cin.fail() || (option < 1) || ...);
--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book

Jul 22 '05 #15

This discussion thread is closed

Replies have been disabled for this discussion.