Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

bool isFileOpenForRead (ifstream& ifs, const string filename) ifs - the input stream representing the file resource filename - the name of the file to open

image text in transcribed

image text in transcribed

bool isFileOpenForRead (ifstream& ifs, const string filename) ifs - the input stream representing the file resource filename - the name of the file to open for reading returns - true if stream is open successfully, false otherwise. int readArrayFromFile(ifstream& ifs, string list[]) ifs - the open stream to read from list - the array to load with values read in returns - the number of elements read into the array Reads a CSV file consisting of integer values followed by a word, each comma delimited and newline terminated. It loads the array with a composite string values made from concatenating the numeric value and word together, e.g. -Apple. Hint: Use the version of the getline(stream, string, delimiter), where the delimiter is a character representing the character the getline() is to read up to. So, for the string , Apple, use a comma, for the delimiter to read the o. If you don't specify the delimiter it defaults to the newline , which allows you to read to the end of the line. Example: If the input file contains the values: 0, Apple 1, Banana 2, Cantelope 3, Date 4, Eggplant 5, Fig The array list will contain the elements "O-Apple", "1-Banana", "2-Cantelope", "3-Date", "4-Eggplant", "5-Fig". bool isFileOpenForRead(ifstream& ifs, const string filename) { ifs.open(filename); return ifs.is_open(); } int readArrayFromFile(ifstream& ifs, string list[]){ int counter = 0; string tempString; string tempNum; while (!ifs.eof()) { getline(ifs, tempNum, ','); getline(ifs, tempString); list[counter] = tempNum tempNum + "-" + tempString; counter += 1; } return counter; }

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

Advances In Databases And Information Systems 14th East European Conference Adbis 2010 Novi Sad Serbia September 2010 Proceedings Lncs 6295

Authors: Barbara Catania ,Mirjana Ivanovic ,Bernhard Thalheim

2010th Edition

3642155758, 978-3642155758

More Books

Students also viewed these Databases questions