isnumeric

Discussion in 'C++' started by Kenny, Jun 3, 2004.

  1. Kenny

    Kenny Guest

    Hello,

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

    thanks

    ken
    Kenny, Jun 3, 2004
    #1
    1. Advertising

  2. Kenny

    Leor Zolman Guest

    On Wed, 2 Jun 2004 21:26:56 -0400, "Kenny" <0m> 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
    Leor Zolman, Jun 3, 2004
    #2
    1. Advertising

  3. Kenny

    Kenny Guest

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

    K
    Kenny, Jun 3, 2004
    #3
  4. 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
    Karl Heinz Buchegger, Jun 3, 2004
    #4
  5. Kenny

    Kenny Guest


    > 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){
    Kenny, Jun 3, 2004
    #5
  6. 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
    Thomas Matthews, Jun 3, 2004
    #6
  7. Kenny

    Leor Zolman Guest

    On Thu, 3 Jun 2004 09:27:31 -0400, "Kenny" <0m> 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
    Leor Zolman, Jun 3, 2004
    #7
  8. Kenny

    Kenny Guest


    > >>

    > >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#.
    Kenny, Jun 3, 2004
    #8
  9. Kenny

    Kenny Guest

    "Thomas Matthews" <> wrote in
    message news:eUFvc.4956$...
    > 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.
    Kenny, Jun 3, 2004
    #9
  10. 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
    Karl Heinz Buchegger, Jun 3, 2004
    #10
  11. 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
    Karl Heinz Buchegger, Jun 3, 2004
    #11
  12. Kenny

    Leor Zolman Guest

    On Thu, 3 Jun 2004 09:57:17 -0400, "Kenny" <0m> 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
    Leor Zolman, Jun 3, 2004
    #12
  13. Kenny

    Kenny Guest

    "Karl Heinz Buchegger" <> wrote in message
    news:...
    > 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
    Kenny, Jun 3, 2004
    #13
  14. Kenny wrote:
    >
    > "Karl Heinz Buchegger" <> wrote in message
    > news:...
    > > 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
    Karl Heinz Buchegger, Jun 3, 2004
    #14
  15. 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
    Thomas Matthews, Jun 3, 2004
    #15
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stephan Bour

    IsNumeric C# equivalent

    Stephan Bour, Nov 5, 2003, in forum: ASP .Net
    Replies:
    12
    Views:
    243,884
    daniefvh
    Jan 26, 2012
  2. martin
    Replies:
    3
    Views:
    10,586
    Kevin Spencer
    Jul 19, 2004
  3. =?Utf-8?B?TXJNaWtl?=

    IsNumeric Function

    =?Utf-8?B?TXJNaWtl?=, Nov 29, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    4,836
    Dan Bass
    Nov 29, 2004
  4. David Lozzi

    Name 'IsNumeric' is not declared???

    David Lozzi, Dec 6, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    4,423
    David Lozzi
    Dec 7, 2004
  5. Steve Kershaw

    Is there any IsNumeric in C#?

    Steve Kershaw, Nov 3, 2005, in forum: ASP .Net
    Replies:
    10
    Views:
    78,471
    Bill.Kanzaki
    Feb 3, 2012
Loading...

Share This Page