Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ file input question:- Note : I had posted the same question a little while ago (you can see it here https://www.chegg.com/homework-help/questions-and-answers/c-file-input-question-want-input-file-format-pasted--preferable-use-instream-loops-getline-q44093432?trackid=cMeCMorG) but the only

C++ file input question:-

Note : I had posted the same question a little while ago (you can see it here https://www.chegg.com/homework-help/questions-and-answers/c-file-input-question-want-input-file-format-pasted--preferable-use-instream-loops-getline-q44093432?trackid=cMeCMorG) but the only problem was the number of lines between each event can vary depending on the file we read in. Meaning that we may have more than three athletes in a different file we have to read in.

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

9th Edition

B01JXPZ7AK, 9780805360479

More Books

Students also viewed these Databases questions

Question

Can workers be trained in ethics? How? Defend your answer.

Answered: 1 week ago