Appending to a file
Recall the several modes that are supported for working with files:
Mode | Operation | Example |
---|---|---|
| Read (the default one) |
|
| Write |
|
| Append |
|
| Read + Write |
|
| Create (error if present) |
|
There are different files present on the computer. You are asked to add some lines to them.
The input contains 2 lines. The first line is the name of the file. The second one is the content we would like to add to that file.
The program needs to first add the specified line to the file and then print the whole content of the file.
Input | doc.txt (initial content) | Output | doc.txt (resulting content) |
---|---|---|---|
doc.txt | This is the first line | This is the first line | This is the first line |
Input | empty.txt (initial content) | Output | empty.txt (resulting content) |
---|---|---|---|
empty.txt | Adding some content | Adding some content |
Input | multiline.txt (initial content) | Output | multiline.txt (resulting content) |
---|---|---|---|
multiline.txt | This is | This is | This is |
Constraints
Time limit: 2 seconds
Memory limit: 512 MB
Output limit: 1 MB