← Back to Streams
Question 593
Lines Containing Text
Lines Containing Text
Write a functionvector<string> linesContaining(const string& filename, const string& sub)that returns, in file order, every line that containssubas a substring. If no line matches, return an empty vector. For a file containing: info boot error disk warn temp error netlinesContaining(..., "error")returns the two lineserror diskanderror 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). Forfatal(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 — 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.