Lines Containing Text
mediumQuestion 593Write a function vector<string> linesContaining(const string& filename, const string& sub) that returns, in file order, every line that contains sub as a substring. If no line matches, return an empty vector. For a file containing:
info boot error disk warn temp error net
linesContaining(..., "error") returns the two lines error disk and error net.
The test prints the size of the returned vector on the first line, then each returned line on its own line (see Expected Output).
For fatal (no matches) the test prints just:
0
Do NOT write a main function.
Expected output
2 error disk error net 0
= newline. The output ends with a newline, so 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.