Test string value - please help

From: ... (..._at_...)
Date: 03/29/04

  • Next message: Ulrich Eckhardt: "Re: Test string value - please help"
    Date: Mon, 29 Mar 2004 04:15:14 GMT
    
    

    I have written the C++ code below to take a string input seperated by
    whitespace then break the input up into string fields. The last four fields
    are numeric; however, if I take the last 4 fields as integers any leading
    "0"s will be lost, keeping them as strings seems to protect the leading "0"s
    from being dropped (For this project it's important each field is read
    correctly inclusive of leading zero's).

    My question is, how do I test the last four fields as being numeric values?
    I don't wish to use a boolean function to perform the test I would just like
    a simple "if" "else" type structure.

    The code is identified as needing help on the 4'th last line.

    Thanks for any assistance!

    istringstream inputString( input );

    string field1;

    string field2;

    string field3;

    string field4;

    string field5;

    inputString >> field1 >> field2 >> field3 >> field4 >> field5;

    cout << "The following was extracted \n"

    << "\n" << field1

    << "\n" << field2

    << "\n" << field3

    << "\n" << field4

    << "\n" << field5 << endl;

    //Test first field of input

    string test1 = ("ISBN");

    if (field1 == test1)

    cout << "Field 1 correct" << endl;

    else

    cout << "Field 1 incorrect" << endl;

    //Test second field of input

    if ???????? //need help here

    cout << "Field 2 correct" << endl;

    else

    cout << "Field 2 incorrect" << endl;


  • Next message: Ulrich Eckhardt: "Re: Test string value - please help"

    Relevant Pages

    • Test string value - please help
      ... I have written the C++ code below to take a string input seperated by ... whitespace then break the input up into string fields. ... I don't wish to use a boolean function to perform the test I would just like ... The code is identified as needing help on the 4'th last line. ...
      (comp.lang.cpp)
    • Re: Test string value - please help
      ... > whitespace then break the input up into string fields. ... > I don't wish to use a boolean function to perform the test I would just ... in decimal digits. ...
      (comp.lang.cpp)
    • Re: Requesting advice how to clean up C code for validating string represents integer
      ... you are assuming the string is meant to have only one data item. ... optionally with whitespace around it either/both way. ... I'll have to remember that paradigm if and when I ever ask a user ... The only place I used implicit int was in return value for main, ...
      (comp.lang.c)
    • I am having a hard time with this code...
      ... delimited by whitespace, which consists of spaces, tabs, ... ; character read was ... ;string printed to report ... Subroutine to get the next character from the standard input. ...
      (alt.lang.asm)
    • FAQ 4.32 How do I strip blank space from the beginning/end of a string?
      ... How do I strip blank space from the beginning/end of a string? ... replace all the leading or trailing whitespace with nothing. ... so the newline disappears too. ... The perlfaq-workers, a group of volunteers, maintain the perlfaq. ...
      (comp.lang.perl.misc)