Log Reader Class
hardQuestion 596Create a class LogReader that loads a log file in its constructor. Each line of the file starts with a level word such as INFO, WARN or ERROR, followed by a space and a message:
INFO boot ok ERROR disk full INFO user login ERROR net down
Implement:
- LogReader(const string& filename): opens the file and stores every line.
- bool loaded() const: returns true if the file was opened successfully, false otherwise.
- int count(const string& level) const: returns how many stored lines begin with the text level.
- string firstError() const: returns the message of the first stored line that begins with ERROR (the text after ERROR ), or the string none if there is no such line.
The test prints loaded() as true or false, then count("ERROR"), then firstError(), each on its own line. For the file above (see Expected Output).
For the path missing_dir/log.txt the test prints false, 0 and none.
Do NOT write a main function.
Expected output
true 2 disk full false 0 none true 0 none
= newline. The output ends with a newline, so print one after the last line.
Your output
Run your code to see the output here...