Question: C++ file input question:- I want to input a file that is in the format pasted below. It is preferable to use instream and a
C++ file input question:-
I want to input a file that is in the format pasted below. It is preferable to use instream and a while loops such as, getLine is the last option. How do I input this in a way where I can get data for each event separately (because later they need to be calculated in different ways):
CODE (I don't know how to do it exactly but I know we have to do it in a way similar to this):
std::ifstream in_str();
if (!in_str.good()) { std::cerr << "Can't open " << argv[3] << " to read. "; exit(1); }
if(in_str >> event >> event_name ){
}
while(in_str >> first_name >> last_name >> country >> score){ }
File:
event POLE_V Andrei Krauchanka BLR 5.00 Bryan Clay USA 5.00 Leonel Suarez CUB 4.70
event JAVELIN_T Leonel Suarez CUB 73.98 Bryan Clay USA 70.97 Andrei Krauchanka BLR 60.23
event 1500_METERS Andrei Krauchanka BLR 4:27.47 Leonel Suarez CUB 4:29.17 Bryan Clay USA 5:06.59
event SHOT_P Bryan Clay USA 16.27 Leonel Suarez CUB 14.49 Andrei Krauchanka BLR 14.39
event HIGH_J Andrei Krauchanka BLR 2.11 Leonel Suarez CUB 2.05 Bryan Clay USA 1.99
event 400_M Andrei Krauchanka BLR 47.30 Leonel Suarez CUB 47.91 Bryan Clay USA 48.92
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
