← Back to Streams
Question 596
Log Reader Class
Log Reader Class
Create a classLogReaderthat loads a log file in its constructor. Each line of the file starts with a level word such asINFO,WARNorERROR, 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: returnstrueif the file was opened successfully,falseotherwise. -int count(const string& level) const: returns how many stored lines begin with the textlevel. -string firstError() const: returns the message of the first stored line that begins withERROR(the text afterERROR), or the stringnoneif there is no such line. The test printsloaded()astrueorfalse, thencount("ERROR"), thenfirstError(), each on its own line. For the file above (see Expected Output). For the pathmissing_dir/log.txtthe test printsfalse,0andnone. 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 — print one after the last line.
Hints4 available
Sign in to use hintsTopics:
Streamsifstream
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.