Fins Vector

Read a line in C++ from file?
I am new to C++ and am getting tripped up over a small part of an assignment. I haven’t learned about vectors and have just started on arrays so this shouldn’t be too hard.
I ask a user for an item. Given that item I want to look up data from a file on that item and perform calculations. How do I read the pertinent line?
For example the user inputs the string ‘itema’
I need to read a, b and c via fin for this line so I can make some calculations that will be outputted to a different file.
Each item name has a different length so I can’t just tell it to read based on the number of characters.
Given a .txt data file:
itemx 12 46 56
itemy 65 35 97
itemz 87 23 76
Thus is what I do:
#include
string item;
int x,y,z;
while ( (inFile>>item) ){
inFile>>x>>y>>z;
if( item == searchItem ) func(item,x,y,z);
}
The expression (inFile>>item) returns true when the read is sucessful and false otherwise. This way you don’t have to know how big the text file is.
the >> operator skips over space and just reads the token.
Future Fins – Vector 3/2, 3/2/1, Scimitar and Gerry Lopez
|
|
FUTURE FINS EA 450 BLACK STIX Vector II blackstix stick $94.95 |
|
|
FUTURE FINS RUSTY BLACK STIX Vector II blackstix stick $94.95 |
|
|
Future Fins Vector II FSG 415 Super Grom surfboard V2 2 $41.95 |
|
|
Oceanic Vector Open Heel Scuba Fins-Sale! $49.10 |
|
|
Futures Vector 2 F4 437, Surfboard Fin Set, Brand New w/Case Thruster Fins Surf $34.95 |
|
|
Futures Vector II F4 437 Surfboard Fins Set of Three $32.99 |
|
|
FUTURE FINS VF4 3/2 HATCHET VECTOR SURFBOARD 3 FIN – BRAND NEW SURFING KEEL $49.99 |
|
|
FUTURE FINS VF 3/2/1 HATCHET VECTOR SURFBOARD 3 FIN – BRAND NEW SURFING KEEL $49.99 |
|
|
FUTURE FINS SOLUS SURFBOARD 3 FIN RTM VECTOR – BRAND NEW SURFING KEEL $109.99 |
|
|
FUTURE FINS V2 F4 SURFBOARD 3 FIN RTM VECTOR II – BRAND NEW SURFING KEEL $75.99 |
|
|
Quantum by American SportWorks – 150cc 9.9hp Full Suspension Go Kart $2,912.01 Offering all the sophistication of a high-performance ATV in a compact package, the Quantum full-suspension go-kart is a great ride for people ages 12 and older. The Quantum is outfitted with such features as a dual-wheel, automatic torque-converter drive that’s perfect for hills, grass, mud, sand, and other tough terrain, along with a 150cc, 9.9-horsepower, air-cooled engine with an electric star… |
|
|
Futures Vector II F4 437 Fins Set of Three White $33.00 An all around template for small to medium surf. The VII Foil generates lots of speed, perfect for in the pocket surfing. Natural strong composite material with greater flex and rebound characteristics. Set of three…. |
|
|
Futures Vector II F4 437 Tri-Quad Fin Set White (set of five) $54.00 A perfectly balanced template for the average size rider. Stability and speed along with a forgiving outline can be used as an explosive setup for quads, thrusters or tri-quads in most conditions…. |