Test string value - please help
From: ... (..._at_...)
Date: 03/29/04
- Previous message: Old Wolf: "Re: error: unknown field `close' specified in initializer"
- Next in thread: Ulrich Eckhardt: "Re: Test string value - please help"
- Reply: Ulrich Eckhardt: "Re: Test string value - please help"
- Reply: Chris \( Val \): "Re: Test string value - please help"
- Reply: B. v Ingen Schenau: "Re: Test string value - please help"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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;
- Previous message: Old Wolf: "Re: error: unknown field `close' specified in initializer"
- Next in thread: Ulrich Eckhardt: "Re: Test string value - please help"
- Reply: Ulrich Eckhardt: "Re: Test string value - please help"
- Reply: Chris \( Val \): "Re: Test string value - please help"
- Reply: B. v Ingen Schenau: "Re: Test string value - please help"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|