Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

could someone fix this for me? int fileLoadRead(string filename) { ifstream in(filename.c_str()); if(!in.is_open()) { return -1; } else { int count =0; string line; while(getline(in,line))

could someone fix this for me?

int fileLoadRead(string filename) { ifstream in(filename.c_str()); if(!in.is_open()) { return -1; } else { int count =0; string line; while(getline(in,line)) { count=count+1; } in.close(); return count; } }

image text in transcribed

image text in transcribed

image text in transcribed

Write a function fileLoadRead that reads a file. The function takes one parameter, the name of the file filename . The function returns the number of lines in the file If the file was not opened successfully, return -1 If the file exists but is empty (contains no non-newline characters), return 0 If the file exists and is not empty, return the number of lines. Include all the lines in your count even those that are blank For Example Given a file called myFile.txt with the following content hola ciao hello hallo the function call fileloadRead"myFile.toxr) would return 6

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

Database Internals A Deep Dive Into How Distributed Data Systems Work

Authors: Alex Petrov

1st Edition

1492040347, 978-1492040347

Students also viewed these Databases questions