← Back to Streams
Question 591
Read a Config Value
Read a Config Value
A configuration file holds onekey=valuepair per line with no spaces around the=: host=localhost port=8080 debug=true Write a functionstring getValue(const string& filename, const string& key)that returns the value whose key matcheskeyexactly (the whole text before the=), or the stringnot foundif no line has that key. For the file above,getValue(..., "port")returns8080andgetValue(..., "user")returnsnot 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
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.