Question: What's shown below is what I'm given. I also need this to be written in C++. -------------------------------------------------------------------------- Lab5Functions.cpp = #include Lab5Header.h #include bool openFile(string fileName,

 What's shown below is what I'm given. I also need this

What's shown below is what I'm given. I also need this to be written in C++.

--------------------------------------------------------------------------

Lab5Functions.cpp =

#include "Lab5Header.h" #include bool openFile(string fileName, ifstream &inFile) { //get the size of the string representing file name int n = fileName.length(); // declaring character array char char_array[n + 1]; // copying the contents of the // string to char array strcpy(char_array, fileName.c_str()); //check if you can open the file inFile.open(char_array); if (inFile.fail()) return false; else return true; } void displayError(string message){ std::cerr

string readFile(ifstream &inputFile){ string line; getline(inputFile,line); cout

}

Lab5Header.h =

#include #include #include #include using std::cout; using std::string; using std::ifstream;

bool openFile(string fileName, ifstream &inputFile); string readFile(ifstream &inputFile); void extractAndDisplay(string line); void displayError(string message);

main.cpp =

#include "Lab5Header.h"

int main() { ifstream inputFile; string fileName="data.txt"; string line; if (openFile(fileName,inputFile)) { while (!inputFile.eof()){ line =readFile(inputFile); extractAndDisplay(line); } } else displayError("File Open Error"); }

data.txt =

This is Line 1 Followed by Line 2 Next comes Line 3

You need to write a program that reads lines from a file and extracts the tokens in each line. You need to declare and initialize and instringstream object with each line that is read from the file and use the stream extraction operator

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!