Answered step by step
Verified Expert Solution
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; } }
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 6Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started