CJCoding With Joseph
15free / daySign inCreate account

Read a Config Value

A configuration file holds one key=value pair per line with no spaces around the =:

host=localhost
port=8080
debug=true

Write a function string getValue(const string& filename, const string& key) that returns the value whose key matches key exactly (the whole text before the =), or the string not found if no line has that key. For the file above, getValue(..., "port") returns 8080 and getValue(..., "user") returns not found.

The test prints the returned string on its own line, for example (see Expected Output).

Do NOT write a main function.

Expected Output:

8080
not found

= 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.