(Solved):Create a file with 20 lines of text and name it lines.txt. Write a program to read this file lines.txt and write the text to a new file, numbered_lines.txt, that will also have line numbers at the… View Answer…

 

Question

Create a file with 20 lines of text and name it lines.txt.

Write a program to read this file lines.txt and write the text to a new file, numbered_lines.txt, that will also have line numbers at the beginning of each line.

Example:

Input file: lines.txt

Line one

Line two

Expected output file:

1 Line one

2 Line two

 

EXPERT ANSWER

Here is a C++ program that solves the given problem. It uses C++ file operation to process the input file

Scroll to top