CJCoding With Joseph
15free / daySign inCreate account

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 same fstream object and prints the numbered notes.

1. Open notes.txt with an fstream in ios::in | ios::out | ios::trunc mode.
2. Read every line from cin with getline and write each one to the file followed by a newline.
3. Move the read position back to the start with seekg(0).
4. Read the file line by line with getline and print each line as N: 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
Topics:
Streamsfstream
📥 Auto-Input:
milk\neggs\n
This input is automatically fed to your program's stdin
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.