CJCoding With Joseph
15free / daySign inCreate account

Lines Containing Text

Write 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 — print one after the last line.

Hints4 available
Topics:
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.