← Back to Streams
Question 663
Notes from stdin
Notes from stdin
Write a program that reads lines from standard input until the input ends, stores them in a file, then reads the file back through the samefstreamobject and prints the numbered notes. 1. Opennotes.txtwith anfstreaminios::in | ios::out | ios::truncmode. 2. Read every line fromcinwithgetlineand write each one to the file followed by a newline. 3. Move the read position back to the start withseekg(0). 4. Read the file line by line withgetlineand print each line asN: text, where N starts at 1 (a colon and a single space after the number). Input: one note per line, for example: milk eggs For that input the program prints the output shown in Expected Output.
Expected Output:
1: milk 2: eggs 1: call mom 2: buy bread 3: pay rent
= newline. The output ends with a newline — print one after the last line.
Hints4 available
Sign in to use hintsTopics:
Streamsfstream
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.